Click here to Skip to main content
12,304,823 members (62,797 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: JScript.NET PHP MySQL
I have a series of three List Boxes, The first box is loading properly, however; the second and the third are loading but not filtering based on the previous selection. The tables are as such;

tblRestaurants
RestID
RestName

tblLocations
LocationID
RestID
CityID
AreaID

tblCities
CityID
CityName

tblAreas
AreaID
AreaName

I am using a function as well:

function createoptions($table , $id , $field , $condition_field , $value)
{
    $sql = sprintf("select * from $table WHERE $condition_field=%d ORDER BY $field" , $value);
    $res = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($res) > 0) {
        while ($a = mysql_fetch_assoc($res))
        $out[] = "{optionValue: {$a[$id]}, optionDisplay: '$a[$field]'}";
        return "[" . implode("," , $out) . "]";
    } else
 
        return "[{optionValue: -1 , optionDisplay: 'No result'}]";
}
 
if (isset($_GET['tblRestaurants'])) {
    echo createoptions("tblLocations" , "CityID" , "Street" , "RestID" , $_GET['tblRestaurants']);
}
 

if (isset($_GET['AreaBox'])) {
    echo createoptions("tblAreas" , "AreaID" , "AreaName" , "AreaID = tblLocations.AreaID" , $_GET['tblLocations']);
}
 
die();

And this is to build the three Listboxes:
<form method = " post=">
<br mode=" hold=" />        
<select name = " restname=" id=" restid=">
<br mode=" -1=">--Select--</option>
<br mode=" tblrestaurants=", " cityid="><br mode=" tbllocations=", " areaid="><br mode=">
Posted 6-Jan-13 9:53am
Edited 7-Jan-13 4:34am
v4
Comments
Member 7766180 6-Jan-13 15:55pm
   
Here is the Listbox code.

<form method = "post">
<select name = "RestName" id="RestID">
<option value="-1">--Select--</option>
createoptions("tblRestaurants", "RestID", "RestName");
?>
</select>
<select id = "RestID" id="CityID">
<option value="-1">--Select--</option>
createoptions("tblLocations", "RestID", "CityID");
?>
</select>
<select id="RestID" id="AreaID">
<option value="-1">--Select--</option>
createoptions("tblLocations", "RestId", "AreaID");
?>
</select>
</form>
DaveAuld 7-Jan-13 3:44am
   
Put the list box code back into your original question for using the "improve question" button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160530.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100