Jump to content

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

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.