Hello, I've been working on this piece of code for quite a while. Essentially it is a Search Tool which pulls Mobile Home information from a database and displays listings based on the users input. When the results page attempts to acquire variables from the Search Tool, it only displays results based off of a single variable, not all of them, which needless to say doesn't give the correct listings. Here is an example snippet of the code I'm using for the Search Tool:
Here is the snippet of code I'm using for the form to activate my results page:
Here is the snippet for the Results Page:
I hope this is enough information and that my comments have helped explain some of the problems I'm currently experiencing with this. I've exhausted all of my resources, and am desperately seeking an answer to this problem. Any help, even an idea or small working function would be greatly appreciated. Thank you very much for your time.
Code:
include("misc.inc");
\* Connection Code *\
$cxn = mysqli_connect($host,$user,$passwd,$dbname) #14
or die ("couldn't connect to server");
/* Select all categories from Homes table */
$query = "SELECT * FROM Homes"; #18
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query."); #20
/* Extract all rows from table */
while($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "Variable Display: $Width\n"; //<-- This is the tester code I used to see if it actually returned all of the variables I need, and it successfully outputs all of them in sequence
}
Code:
echo "<form action='homeresults.php' method='POST'>\n"; echo " <select name=\"Beds\">\n"; echo " <option selected=\"selected\" value=\"0\">Any</option>\n"; echo " <option value=\"1\">1</option> \n"; echo " <option value=\"2\">2</option> \n"; echo " <option value=\"3\">3</option> \n"; echo " <option value=\"4\">4</option>\n"; echo " <option value=\"5\">5</option></select>\n"; //<---I thought this code worked when I originally tested the Search Tool, but it defaults to 0, which returns all results (Same for Baths) /* This code is for Width, where I'm currently working on getting the "Any" option to work. The code works just fine for the other options, but I'm trying to get the generic "Any" option to return all results, but when I send $Width to the results page, it only returns one variable, hence only one set of results. This same rule will apply to all of the future code snippets to create multiple "Any" values.*/ " <b><u>Width:\n"; echo "</td>\n"; echo "<td>\n"; echo "<select name='Width'>\n"; echo " <option selected=\"selected\" value=\"$Width\">Any</option>\n"; echo " <option value='Single-Wide'>Single-Wide</option> \n"; echo " <option value='Double-Wide'>Double-Wide</option> \n"; echo " <option value='Triple-Wide'>Triple-Wide</option> </select>\n";
Here is the snippet for the Results Page:
Code:
/* Select Homes of the given type */
$query = "SELECT * FROM Homes
WHERE Beds>=\"{$_POST['Beds']}\" and Baths>=\"{$_POST['Baths']}\" and Width=\"{$_POST['Width']}\""; //<---This code helps me select only the values that the user has asked for to decrease load time.
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query.");
/* Display results in a table */
$Width=array('Single-Wide','Double-Wide','Triple-Wide'); //<----This was my attempt to get the SQL Query to select all values from the table, and output all Widths to the table, which didn't work, but I'm unsure if my syntax or execution is incorrect, so I've left this in just in case it will double as a solution (Provided a fix can be offered of course.)
echo "<br>\n";
/* This code just performs a loop for all of the arrays that are created as a result of my SQL Query. This code works just fine, and does it's job by generating a new table for each of my listings, but only works correctly when the variables get through, which is where my problem is originating */
while($row = mysqli_fetch_assoc($result))
{
extract($row);
/* display row for each pet */
echo "<table width=\"755px\" background=\"http://bytes.com/images/sebg.gif\">\n";
echo "<tr>\n";
echo "<td>\n";
echo " <table width=\"95%\">\n";
echo " <td rowspan=\"5\" align=\"center\"><a href=\"{$row['Model#']}.php\"><img border=\"1\" src=\"http://bytes.com/images/models/{$row['Model#']}Thumb.gif\"></a><br>\n";
echo " <b><u><font size=\"1\">Virtual Tour:<br></u><a href=\"{$row['TourLink']}\"><img src=\"{$row['TourPic']}\">\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td><font size=\"+1\"><b><u>{$row['ModelName']}</b></u><br>\n";
echo " {$row['Width']}<br>\n";
echo " {$row['Beds']} Bed / {$row['Baths']} Bath<br>\n";
echo " {$row['Area']} Sq. Ft.<br>\n";
echo " Available on Lot?: <a href=\"{$row['Model#']}.php\">{$row['OnLot']}</a><br>\n";
echo " \n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " \n";
echo "</td>\n";
echo "<td align=\"center\">\n";
echo " <table>\n";
echo " <tr>\n";
echo " <td><center><font size=\"+1\"><b><u></b></u><img src=\"{$row['Floorplan']}\"><br>Floorplan\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td align=\"center\"><a href=\"{$row['ModelLink']}\">-View Model in Detail-</a>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
}
Comment