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.

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.

thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.