php form help- multiple <select >

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
uilleann
Forum Newbie
Posts: 10
Joined: Fri Jul 03, 2009 10:51 am

php form help- multiple <select >

Post by uilleann »

hello there, I am new to this language and am looking for some help. I am creating a form that will select locations from mysql. The table is already populated and I already have the first select defining countries. What I have been trying to do, which I need help on, is create a <select> (for the states) that is dependent off another select(country).
The table is set up like this: location_id(key),country,state,city
this is what I have so for regarding php:
<select name="country">
<?php
mysql_connect(*************************) or die(mysql_error());
mysql_select_db("_root") or die(mysql_error());

$query = ("SELECT country FROM location_root") or die("something messed up");
$result = mysql_query($query);


while ($row = mysql_fetch_array($result))
{

$categories[] = $row['country'];

}

$newData = array_unique($categories);

foreach ($newData as $dropDown)
{
echo "<option>" . $dropDown . "</option>\n";
}

?>
</select>


if anyone could help me, it would be great! thanks
Post Reply