Jump to content

PHP and mySQL Dropdown Box Help


Teammuffin

Recommended Posts

Hey guys.

 

I am new to PHP and I have figured out how to populate a dropdown box with data from my database but now I want to create another dropdown box with data from my database but I want it to be data that depends on the data from the first drop down box.  I am making code for a supply order for a website I am making for tafe and I filled in the first drop down box with the supplier names and now I want a second drop down box of all the products that that supplier is supplying us.  I cannot for the life of me work out how to do this and I have no idea what to search to get this.  Any help will be greatly appreciated.  I will show you the code for my first dropdown box.

 

<?php
$db_host = "localhost";
$db_username = "root";
$db_password = "";
$db_name = "ocs";
@mysql_connect("$db_host","$db_username","$db_password") or die("Could not connect to MySQL");
@mysql_select_db("$db_name") or die("Cannot find database");
$query = "SELECT ProductID FROM products";
$result = mysql_query($query) or die(mysql_error());
$dropdown = "<select name='products'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['ProductID']}'>{$row['ProductID']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
?> 

 

Thanks a lot

-Teammuffin

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.