0

I'm trying to teach myself a bit more php/mysql so that I can implement better usability on my osCommerce site.
I've set up a bit of space on the web server and the db server so that I can play about with stuff and I'm close to doing what I want to but I've hit an impasse.

I have a drop down menu populated with three categories from one table in my db and another for subcategories of which there are five for each main category.

//categories dropdown 
$result = mysql_query ("SELECT * FROM dependant_dropdown_test_parent"); 
echo "<h1>Test</h1><table><tr><td>"; 
echo "Categories</br><select>Categories"; 
echo "<option value='0'>Select a category</option>"; 
while ($row = mysql_fetch_array ($result)) 
  { 
  echo "<option value=" .$row['parent_id']. ">" . $row['parent_value']. "</option>"; 
  } 
echo "</select>"; 
echo "</td><td>"; 
 
//sub-categories dropdown 
$result = mysql_query ("SELECT * FROM dependant_dropdown_test_child"); 
echo "Sub-categories</br><select>Sub-categories"; 
echo "<option value='0'>Select a sub-category</option>"; 
while ($row = mysql_fetch_array ($result)) 
  { 
  echo "<option value=" .$row['child_id']. ">" .$row['child_value']. "</option>"; 
  } 
echo "</select></td></tr></table>";

I want to take the selected "parent_id" from the first drop down and modify the second query so that it ends with "WHEN parent_id = $...".
I also want to hide the second one until a selection has been made on the first (or if there was a category with no subcategories), but I'm happy to take it one step at a time.
I appreciate any help.
Regards,
Sam

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by s.butler1
0

For selecting ID, you may refer this thread.

Store the selected ID in a session variable and pass this value back to the second query.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.