Welcome to WebmasterWorld Guest from 54.90.204.233

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Help with Multiple drop down lists

mulitiple drop down list

     
8:19 pm on Dec 31, 2007 (gmt 0)

New User

10+ Year Member

joined:Dec 31, 2007
posts: 3
votes: 0


A little help would be great.
Through searching, I have managed to create multiple drop down lists, each relying on the previous and all is well. What I can't manage to accomplish is when I click on the final drop down list, I would like to bring data in from another table.

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.

11:21 am on Jan 3, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


Hello Hazzaa, Welcome to WebmasterWorld.

If I understad you correctly, you might need to look into Ajax to solve your problems.

12:06 pm on Jan 3, 2008 (gmt 0)

New User

10+ Year Member

joined:Jan 3, 2008
posts: 8
votes: 0


I've tried experimenting with a similar problem myself. I know there is an onchange function supported by HTML which may be able to support this and I'm pretty sure there is a way of grabbing the selected element through the HTML DOM. I'm new at this so please so if this isn't any help I think Ajax would offer better support too. W3schools has a decent tutorial section on it.
12:29 pm on Jan 3, 2008 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts: 4444
votes: 11


Ajax seems to be the answer.

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

2:45 pm on Jan 3, 2008 (gmt 0)

New User

10+ Year Member

joined:Dec 31, 2007
posts: 3
votes: 0


Thanks for the warm welcome and the responses. I'm new to php and this is why my dilemma. I have found bits and pieces of code online that has helped me this far but can't seem to take the final step to where I need it.

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

}

?>


All is working great. I can get it to pull as many drop downs as I want and can also make the results pull in a drop down list but I need them to pull up in a table so that I can list multiple fields in the final result. I currently have a locator that can find members by zip code search same as a store locator that you may find on different websites. But I would like to add the option of an advanced search to be able to find members by city. This would include the name, state, county, city, address, zip code, phone number and a map to the members location.
2:50 pm on Jan 3, 2008 (gmt 0)

New User

10+ Year Member

joined:Dec 31, 2007
posts: 3
votes: 0


Another thought that just came to mind that may help in this resolution.
The searches this far are tables tied based on state ID. My results table does not have the state or county ID but does have the names. So what I'm trying to do is tie them based on the condition the that state name and county name are the same.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members