2 Drop down lists
Posted: Sun Jan 09, 2011 3:49 am
Hey everyone i'm really sorry i'm posting so many help topics but they all pertain to each other so this is why i haven't resolved the other ones yet. The thing is i have 2 drop down selections and i want the first one to retrieve information from my mysql table and then based on the first selection the second one will appear, right now it just shows all of the categorys and all of the subcategorys, i only want the subcategories to display according to the category selected.
Here is the code
what i want it to do is when a level has been selected it will grab the id on the table and then it will query the subcategory where pid=id but unfortunately i tried putting it to where it will say pid=$id but it doesn't work because when setting the id it is in the while statement then the value is lost, and also even if it did work you would have to refresh the page right? or is it possible to make it to where you dont have to refresh and keeping it all php?
Thank you in advance and i'm so close to having the other posts resolved!
Here is the code
Code: Select all
<?php
include 'Connect.php';
$result = mysql_query( "SELECT id,name FROM category" )
or die("SELECT Error: ".mysql_error());
$options="";
while ($row=mysql_fetch_array($result)) {
$firstvalue=$row["name"];
$id=$row["id"];
$options.="<OPTION VALUE=\"$firstvalue\">".$firstvalue.'</option>';
}
?>
<?php
$results = mysql_query( "SELECT id,name FROM subcategory" )
or die("SELECT Error: ".mysql_error());
$optionss="";
while ($rows=mysql_fetch_array($results)) {
$secondvalue=$rows["name"];
$options1.="<OPTION VALUE=\"$secondvalue\">".$secondvalue.'</option>';
}
?>
<SELECT NAME=p>
<OPTION VALUE=0>
<?php echo $options?>
</SELECT>
<SELECT NAME=q>
<OPTION VALUE=0>
<?php echo $options1?>
</SELECT>
Thank you in advance and i'm so close to having the other posts resolved!