Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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:

PHP
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:
PHP
<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
Updated 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>

</select>
<select id = "RestID" id="CityID">
<option value="-1">--Select--</option>

</select>
<select id="RestID" id="AreaID">
<option value="-1">--Select--</option>

</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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900