herghost Posted October 20, 2009 Share Posted October 20, 2009 Hi all, I would like to have a form that gives you options based on the results of an mysql query. My example is this, say I have a mysql row with the colum name points and the result is 5. How would I populate a form with a drop down box with the options 1 or 5. Ie the user can select either a single point they have or all 5? Thanks Link to comment https://forums.phpfreaks.com/topic/178307-form-variables-from-database-help/ Share on other sites More sharing options...
Lyleyboy Posted October 20, 2009 Share Posted October 20, 2009 Hi Just use something like the demo from the Tizag site. <?php // Make a MySQL Connection $query = "SELECT * FROM example"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['name']. " - ". $row['age']; echo "<br />"; } ?> But now change the while. <select name="DropDown"> <?php // Make a MySQL Connection $query = "SELECT * FROM example"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<option value='"; echo $row['name']; echo "'>"; echo $row['name']; echo "</option>"; } ?> </select> All the bits inside the while could be condensed into one line but I've put it on several here to make it more clear. Link to comment https://forums.phpfreaks.com/topic/178307-form-variables-from-database-help/#findComment-940231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.