Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php sql select problem

Status
Not open for further replies.

shadiadi

Programmer
Dec 19, 2008
4
TH
Hi I have the following php form the second selection item has to relate to the first selection item but i am totally lost here here is the code i have at the moment it is displaying items in the second selection but they are not related to the first item selected.

Code:
<td class="right">
<? 
$sql = "SELECT * FROM tblcatdetails ORDER BY category ASC"; 
$result = mysql_query($sql);
echo '<select name="category">';
while ($row = mysql_fetch_assoc($result)) {
$catid = $row["intCatID"];
$category = $row["category"];
echo '<option value="'.$catid.'">'.$category.'</option>';
}
echo '</select>';
?>

</td></tr>
<tr><td class="left">Sub Category:</td>
<td class="right">
<? 
$sql = "SELECT * FROM tblsubcatdetails where intCatID='$catid' ORDER BY subcategory ASC"; 
$result = mysql_query($sql);
echo '<select name="subcategory">';
while ($row = mysql_fetch_assoc($result)) {
$subcatid = $row["intSubCatID"];
$subcategory = $row["subcategory"];
echo '<option value="'.$subcatid.'">'.$subcategory.'</option>';
}
echo '</select>';
?>
</td></tr>
 
You need to submit your first select box if you want to use the selected option to populate the second select box. Nowhere do I see you actually doing that. Rather you are just pre-populating your second select with a variable that has a value of the last $row from the first query.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top