Jump to content

Dropdown generated from Database information


Ryflex

Recommended Posts

Hi all,

 

Does anyone know if it's possible to generate a dropdown list filled with database information.

I use the following to get the information from the database:

$query                      = "SELECT Name
                               FROM city
                               WHERE member_ID = '$member_ID'";
$result                     = mysql_query($query)
                              or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
     echo $row['Name'] . '<br>';
}

 

Thnx Ryflex

Link to comment
Share on other sites

You are doing it now pretty much just forgetting to add the dropdown... try this:

 

<?php
$query = "SELECT NameFROM city WHERE member_ID = '$member_ID'";
$result = mysql_query($query) or die(mysql_error());

echo '<select name="dropdown">';
while($row = mysql_fetch_assoc($result)){
     echo '<option>'.$row['Name'] . '</option><br>';
}
echo '</select>';
?>

Link to comment
Share on other sites

Hi all,

 

A little addition to my question...

Is it possible to make the dropdown menu in a way that when I click one of the entries it automaticaly uses that value as a submit.

So if I click value 2 the page reloads and $_post the value 2.

 

Thnx Ryflex

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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