Jump to content

Loop and display data help


ShaolinF

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 ?

 

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.