cry of war Posted September 6, 2007 Share Posted September 6, 2007 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) Quote Link to comment https://forums.phpfreaks.com/topic/68197-solved-fill-in/ Share on other sites More sharing options...
Daniel0 Posted September 6, 2007 Share Posted September 6, 2007 <?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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68197-solved-fill-in/#findComment-342857 Share on other sites More sharing options...
cry of war Posted September 6, 2007 Author Share Posted September 6, 2007 so the above will stop after all the ids are gone correct? Quote Link to comment https://forums.phpfreaks.com/topic/68197-solved-fill-in/#findComment-342858 Share on other sites More sharing options...
Daniel0 Posted September 6, 2007 Share Posted September 6, 2007 Yes. mysql_fetch_assoc() will return false when there are no more rows left. The while loop stops if the statement is false. Quote Link to comment https://forums.phpfreaks.com/topic/68197-solved-fill-in/#findComment-342859 Share on other sites More sharing options...
cry of war Posted September 6, 2007 Author Share Posted September 6, 2007 alright thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/68197-solved-fill-in/#findComment-342862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.