boneXXX Posted April 25, 2008 Share Posted April 25, 2008 Hi all, I am trying to do a drop down menu which gets the options from a specific table in the database. Such as there is a table called EventType and this table has a single column that is called Event_Name. I want to make a drop down menu and each option will get a row from the table. In that way users will be able to pick a event from the EventType table. This is I have done so far could you help me on this please? Thanks <? include ("../databaseConnect/dbfuncs.inc.php"); $link = connectToDatabase(); $result = mysql_result("SELECT Event_Name FROM EventType"); $rows = mysql_num_rows($result); echo "<select name='Events'>"; echo "<option>Select Event</option>"; for($x=0; $x = $rows; $x++) { $data = mysql_fetch_row($result); echo "<option value=$data[1]>$data[1]</option>"; } echo "</select><td/>"; ?> Link to comment https://forums.phpfreaks.com/topic/102836-php-mysql-drop-down-menu/ Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 Try <?php include ("../databaseConnect/dbfuncs.inc.php"); $link = connectToDatabase(); $result = mysql_result("SELECT Event_Name FROM EventType"); $rows = mysql_num_rows($result); echo "<select name='Events'>"; echo "<option>Select Event</option>"; while ($row = mysql_fetch_assoc($result)){ echo "<option value='{$row['Event_Name']}'>{$row['Event_Name']}</option>"; } echo "</select><td/>"; ?> Link to comment https://forums.phpfreaks.com/topic/102836-php-mysql-drop-down-menu/#findComment-526802 Share on other sites More sharing options...
boneXXX Posted April 25, 2008 Author Share Posted April 25, 2008 Thank you for the reply but I got these errors Warning: Wrong parameter count for mysql_result() Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource Link to comment https://forums.phpfreaks.com/topic/102836-php-mysql-drop-down-menu/#findComment-526804 Share on other sites More sharing options...
zenag Posted April 25, 2008 Share Posted April 25, 2008 check ur fieldname or database name.. Link to comment https://forums.phpfreaks.com/topic/102836-php-mysql-drop-down-menu/#findComment-526807 Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 You should be using mysql_query() instead of mysql_result(). So change: $result = mysql_result("SELECT Event_Name FROM EventType"); To: $result = mysql_query("SELECT Event_Name FROM EventType"); Link to comment https://forums.phpfreaks.com/topic/102836-php-mysql-drop-down-menu/#findComment-526809 Share on other sites More sharing options...
boneXXX Posted April 25, 2008 Author Share Posted April 25, 2008 Thank you all it is working. <?php include ("../databaseConnect/dbfuncs.inc.php"); $link = connectToDatabase(); $result = mysql_query("SELECT Event_Name FROM EventType"); $rows = mysql_num_rows($result); echo "<select name='Events'>"; echo "<option>Select Event</option>"; while ($row = mysql_fetch_assoc($result)){ echo "<option value='{$row['Event_Name']}'>{$row['Event_Name']}</option>"; } echo "</select><td/>"; ?> Link to comment https://forums.phpfreaks.com/topic/102836-php-mysql-drop-down-menu/#findComment-526869 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.