Jump to content

PHP - MYSQL - Drop Down Menu


boneXXX

Recommended Posts

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

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/>";

?>

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/>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.