Jump to content

[SOLVED] <select> fill in


cry of war

Recommended Posts

I am trying to set up my website so i can take the information form my database and make it fill in a <select> tag with the correct information. I know how to make it so it fills in the data for a selected amount of items but how do I make it so it fills in more then that. Like say my admins add a new item into the database and they dont change the php/html file so the new item is under the <select> tag. I know I can use a loop command but I dont know how to set it so it stops after its gone through all the data. Any help you could give me would be great

 

id             name1                  name2

1              blah                      blah

2            blah blah               blah blah

3         blah blah blah         blah blah blah

...              ...                        ...

 

id is on auto increment and primary key

my admins have a page that inserts data into this table (tables that look like this) so i wont know if they change it or not thats why i was wondering if this could be done

 

INSERT INTO table_blah

VALUES (blah blah blah blah, blah blah blah blah)

Link to comment
https://forums.phpfreaks.com/topic/68197-solved-fill-in/
Share on other sites

<?php
// connect to db here

$result = mysql_query("SELECT * FROM table");
if(mysql_num_rows($result) > 0)
{
echo "<select name='whatever'>\n";
while($r = mysql_fetch_assoc($result);
{
	echo "\t<option value='{$r['id']}'>{$r['name']}</option>\n";
}
echo "</select>";
}
else {
echo "No items in database";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/68197-solved-fill-in/#findComment-342857
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.