Jump to content

drop down answer boxes


mdhlme1

Recommended Posts

Well you should write a code that is something like this...

 


<select name='select_name'>
<?php
  foreach($option_values as $option_value)
   {
     echo "<option>".$option_value."</option>";
   }
?>
</select>

 

 

This will give you all the options in a drop down menu.

 

Thanks

 

Jyot

Well you should write a code that is something like this...

 


<select name='select_name'>
<?php
  foreach($option_values as $option_value)
   {
     echo "<option>".$option_value."</option>";
   }
?>
</select>

 

This will give you all the options in a drop down menu.

 

Thanks

 

Jyot

 

 

that may give the user a dropdown menu, but it will be useless because it has no value="". and, that will only work if the dropdown menu is populated from a hard-coded array. what if he wanted it populated from a database?

 

this is what a dropdown menu should look like if it were populated from a database:

<?php
        $db_conn = mysql_connect('xxx', 'xxx', 'xxx');
        ((!$db_conn) ? (die('could not connect to mysql')) : (''));

        mysql_select_db('your_database', $db_conn) OR die('could not connect to database');

        $sql = "
                SELECT
                        *
                FROM
                        your_table
        ";
        $query = mysql_query($sql) OR die("[{$sql}]<br />\nCaused the following error: <i>". mysql_error() ."</i>\n");

        echo "<form action=\"\" method=\"post\">\n";
        echo "<select name=\"drop_down\">\n";
        while($row = mysql_fetch_array($query)){
                echo "<option value=\"{$row['column1']}\"";
                echo (($_POST['drop_down'] == $row['column1']) (' SELECTED') : ('');
                echo ">{$row['column2']}\n";
        }
        echo "</select>";
        echo "<input type=\"submit\" value=\"Submit\">\n";
        echo "</form>\n";
?>

 

 

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.