Forum Moderators: coopster
A better explanation is this.
I currently have a website with 1500 + members located around the country. I have created 3 drop down lists to get data from mysql.
list 1 = State (table name = state)
list 2 = County (table name = county)
list 3 = City (table name = city)
When I click on the city name, I want all members' located in that city to be listed a table format located on the search page.
I would appreciate any help I can get.
Thanks in advance H.
By the way I heard that some org is working on a soon release of a system that could deliver the same effect without the AJAX constrain
The W3c tutorial relies on passing ID
There are other means more flexible
Look for AJAX classes, many authority sites have posted a few of those.
You should find a bunch of very useful and well developed such classes free to use under the GPL agreement
<?php$state = $county = $city = null; //declare vars
$conn = mysql_connect("localhost", "dbusername", "dbpassword");
$db = mysql_select_db('dbname',$conn);
if(isset($_GET["state"]) && is_numeric($_GET["state"]))
{
$state = $_GET["state"];
}
if(isset($_GET["county"]) && is_numeric($_GET["county"]))
{
$county = $_GET["county"];
}
if(isset($_GET["city"]) && is_numeric($_GET["city"]))
{
$city = $_GET["city"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get">
<!-- state SELECTION BASED ON city VALUE -->
<?php
?>
<select name="state" onChange="autoSubmit();">
<option value="state">Select State</option>
<?php
//POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN city
$sql = "SELECT * FROM cat_state";
$countries = mysql_query($sql,$conn);
while($row = mysql_fetch_array($countries))
{
echo ("<option value=\"$row[state_id]\" " . ($state == $row["state_id"]? " selected" : "") . ">$row[state]</option>");
}
?>
</select>
<?php
?>
<br><br>
<?php
if($state!= null && is_numeric($state))
{
?>
<select name="county" onChange="autoSubmit();">
<option value="county">Select County</option>
<?php
//POPULATE DROP DOWN MENU WITH countyS FROM A GIVEN city, state
$sql = "SELECT * FROM cat_county WHERE state_id = $state ";
$countys = mysql_query($sql,$conn);
while($row = mysql_fetch_array($countys))
{
echo ("<option value=\"$row[county_id]\" " . ($county == $row["county_id"]? " selected" : "") . ">$row[county]</option>");
}
?>
</select>
<?php
}
?>