Jump to content

Recommended Posts

Hey Guys,

 

I want to grab some data from my table and then output it into a dropdown list. I've got the data, I just dont know how to output it into the list. This is what I have done so far:

 

<?
//SELECT Data
$result = mysql_query('SELECT eventName FROM event');
//Error Check
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $result;
    die($message);
	}
// Output Data
while ($row = mysql_fetch_assoc($result)) {
?>

 

<select name="event">Select Event to Edit:
<? <option value="1">Text that will appear in the choices</option> ?>
</select>

 

Link to comment
https://forums.phpfreaks.com/topic/87493-loop-and-display-data-help/
Share on other sites

<?



//SELECT Data



$result = mysql_query('SELECT eventName FROM event') or die("Error: ".mysql_error());
// Error check is above....



// Output Data
echo "<select name=\"event\">Select Event to Edit:";
while ($row = mysql_fetch_assoc($result)) {

echo "<option value=\"".$row['id']."\">".$row['event']."</option>";

}

echo "</select>";
?>

 

that should be right, any questions.. ask.

Thanks, it worked. I want to do another thing. What I want to do is once the dropdown is loaded, the user can select whichever option he wants and it will automatically load the DB values for that option into some text boxes. How would I go about doing that ?

 

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.