Getting database entries from a combo box?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Getting database entries from a combo box?

Post by cturner »

Can someone please tell me how I can get database entries from a combo box? Thanks in advance.

Here is some code that I am working with:

Code: Select all

require "config_admin.php";
	echo "View products in: ";
	$sql2 = mysql_query("SELECT * FROM tbl_category") or die ("Could not select the database because: " . 	mysql_error());
	// display the categories combo box
	while($row = mysql_fetch_array($sql2)){
		echo "<select name=\"selectCategory\" id=\"selectCategory\" class=\"select\">";
		echo "<option value=\"all\" selected>All Categories</option>";
		echo "<option value=".$row[category].">".$row[category_name]."</option>";
		echo "</select>";
	}
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

:?: Try asking that again... except this time... elaborate.
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post by waradmin »

Well, if I understand correctly you just need to complete the <form> tag's, and have the value's passed by say $_POST to another file, or even the same file and have a database query execute using the POST values.
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post by cturner »

After adding data to a database and displaying the data in a combo box and when the user selects a entry from the combo box I am wanting that entry to do something. For example display a certain amount of products from another database table.
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

your logic is partially right, but the order of your commands isnt.
Try this:

Code: Select all

echo "<select name=\"selectCategory\" id=\"selectCategory\" class=\"select\">";
echo "<select name=\"selectCategory\" id=\"selectCategory\" class=\"select\">";
$result = mysql_query("your query here");
while($row = mysql_fetch_array($result)
{
echo "<option value=".$row[category].">".$row[category_name]."</option>";
}
echo "</select>";
You dont wanna create and close your select inside the while, thats not good :)
Post Reply