wazza91 Posted April 13, 2011 Share Posted April 13, 2011 hi i have this code here and i was wondering how i could make it print out the values from my database using a drop down menu. i no this is probably very basic but im a real novice at php and sql. <?php mysql_connect('localhost', 'root', ''); mysql_select_db('charity_data'); $result = mysql_query('select * from donations'); ?> <select name="selectname"> <?php $i = 0; while ($i < mysql_num_fields($result)){ $fieldname = mysql_field_name($result, $i); echo '<option value="'.$fieldname.'">'.$fieldname.'</option>'; $i++; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/233604-printing-tables/ Share on other sites More sharing options...
Rifts Posted April 13, 2011 Share Posted April 13, 2011 <?php mysql_connect('localhost', 'root', ''); mysql_select_db('charity_data'); $result = mysql_query('select * from donations'); ?> <select name="selectname"> <?php while ($row = mysql_fetch_assoc($result)){ echo "<option value='whatever'>".$row['databasefield']."</option>"; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/233604-printing-tables/#findComment-1201172 Share on other sites More sharing options...
wazza91 Posted April 13, 2011 Author Share Posted April 13, 2011 thanks but there is nothing showing up in the dropdown menu. Quote Link to comment https://forums.phpfreaks.com/topic/233604-printing-tables/#findComment-1201208 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.