0

I´m currently developing an online real estate market and am having trouble to navigate from the overview site, where all real estate offerings are displayed to the detail site.

What works is that all offerings are displayed on wohnen_haus.php. What´s weird is that sometimes, when I open an offering site, two detail pages are displayed... There must be something wrong with the php-part as I tried the sql-statements manually in the console of phpMyAdmin and they brought the desired results.

Any ideas what could be wrong with the php?

This is my main page:

wohnen_haus2.php

                require("../model/House2.php"); //contains the class "House"
                require("../func/func_properties.php"); //contains the array $properties_array that contains all offerings
                require("../func/FavoriteList.php");


                $House = new House2;
                $House->display($house_sale);
                $House->display($house_rent);

This is where I define displayHouseSale:

House2.php

class House2 {

public function display ($properties_array)
{

if (isset($_GET['view_property'])) {
    $property_id = $_GET['view_property'];


    // IF ID IS SET, DISPLAY DESIRED PROPERTY
    if (isset($properties_array[$property_id])) {
        echo
            "<table border='1' cellspacing='0' cellpadding='2'>
                    <tbody>
                    <tr> <td colspan='2' > <a href='#'>" . $properties_array[$property_id]['title'] . "</td> </tr>
                    </tbody>
             </table>";
}

    // IF ID IS SET WRONG, DISPLAY ERROR-MESSAGE
    else
    {
        echo "Invalid property!";
    }

}


// IF ID IS NOT SET, DISPLAY ALL PROPERTIES
else {
    echo "<h3>Häuser</h3>";

    // LOOP THORUGH THE ARRAY PROVIDED BY "func_properties.php"
    // TO DISPLAY ALL OF THE PROPERTIES
    foreach ($properties_array as $id => $property) {
        echo
        "<a href='wohnen_haus2.php?view_property=' " . $id . "> <h1>" . $property['title'] . "</h1> </a>";
    }
}

This is where I get the data from the database:

func_properties.php

include("../inc/config.php");
require("../inc/db_connect.php");


// Requests all houses for sale
$stmt = $dbh->prepare("
    SELECT id, title, description, neighbourhood, vacant_from,            street, housenumber, postalcode, city, construction_year, rooms, levels, bathrooms, kitchens, living_space, agent, image,
    property_size, house_type,
    deposit, pets, net_rent, heated_rent
    FROM tbl_OFFERING o, tbl_PROPERTY_TYPE_house pth, tbl_OFFERING_FORMAT_rental ofr
    WHERE o.id = ofr.offering_id
    AND o.id = pth.offering_id;
    ");
 $stmt->execute();
 $house_rent = $stmt->fetchAll(PDO::FETCH_ASSOC);


//Requests all houses for rent
$stmt = $dbh->prepare("
    SELECT
    id, title, description, neighbourhood, vacant_from, street,    housenumber, postalcode, city, construction_year, rooms, levels, bathrooms, kitchens, living_space, agent, image,
    property_size, house_type,
    sales_price, brokers_commission
    FROM tbl_OFFERING o, tbl_PROPERTY_TYPE_house pth,    tbl_OFFERING_FORMAT_sale ofs
    WHERE o.id = ofs.offering_id
    AND o.id = pth.offering_id");
 $stmt->execute();
 $house_sale = $stmt->fetchAll(PDO::FETCH_ASSOC);
Greta
  • 300
  • 1
  • 10

0 Answers0