I get great tips from this site but am really struggling with something now and need some expert help, I am learning so please be nice 🙂 anyway, i have a script that dynamically changes 3 drop down menus depending on what a user selects, i have a database with one table that i can query no problem (mysql) so far so good, the problem is that i cant seem to produce results based on what the user selects from the drop down menu, i dont see any records and i am not even sure if i can use the query with my menu items having numbers as opposed to words, i would appreciate even a small help, i just need to get one bit working then i think i can manage = thanks alot to all
<?php
// Make a MySQL Connection
mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("travel") or die(mysql_error());
$valid_class = array('4', '6', '7', '1', '5', '3');
$valid_category = array('4.1.9', '4.1.7', '4.1.8', '4.1.6', '4.1.5',
'4.1.2', '4.1.1', '4.1.10', '4.1.4'' 4.1.3', );
$where = array();
$where[] = 'menuOne = "' . mysql_real_escape_string($_POST['menuOne']) . '"';
;
if (in_array($_POST['menuOne'], $valid_class))
{
$where[] = 'menuOne = "' . $_POST['menuOne'] . '"';
}
if (in_array($_POST['menuTwo'], $valid_category))
{
$where[] = 'menuTwo = "' . $_POST['menuTwo'] . '"';
}
// Retrieve all the data from the "category" table
$result = 'SELECT * FROM records WHERE ' . implode(' AND ', $where);
if(!isset($result))
{
mysql_affected_rows($result);
}
echo "\n <table border=1 width=100%>";
echo "\n<tr>" .
"\n\t<th>ID</th>" .
"\n\t<th>Name</th>" .
"\n\t<th>Address</th>" .
"\n\t<th>Location</th>" .
"\n\t<th>Email</th>" .
"\n\t<th>Telephone</th>" .
"\n\t<th>Website</th>" .
"\n\t<th>Open Season</th>" .
"\n\t<th>Destination</th>" .
"\n\t<th>Categories</th>" .
"\n</tr>";
while($row = @ mysql_fetch_array($result)) {
echo "\n<tr>" .
"\n\t<td>{$row["ID"]}</td>" .
"\n\t<td>{$row["Name"]}</td>" .
"\n\t<td>{$row["Address"]}</td>" .
"\n\t<td>{$row["Location"]}</td>" .
"\n\t<td>{$row["Email"]}</td>" .
"\n\t<td>{$row["Telephone"]}</td>" .
"\n\t<td>{$row["Website"]}</td>" .
"\n\t<td>{$row["Open Season"]}</td>" .
"\n\t<td>{$row["Destination"]}</td>" .
"\n\t<td>{$row["Categories"]}</td>";
}
echo "\n</table>";
?>
In order for your mysql query
$result = 'SELECT * FROM records WHERE ' . implode(' AND ', $where);To work you need to actually send it.
mysql_query($result)What you have currently
while($row = @ mysql_fetch_array($result)) {Is designed to be run on the result of a msql_query call. eg
$query= mysql_query($result);then run
while($row = @ mysql_fetch_array($query)) {So thats your only problem as far as i can see, you have just left out the query.
Hope that helps, feel free to ask for more details.