ShaolinF Posted January 24, 2008 Share Posted January 24, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/87493-loop-and-display-data-help/ Share on other sites More sharing options...
MikeDXUNL Posted January 24, 2008 Share Posted January 24, 2008 <? //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. Quote Link to comment https://forums.phpfreaks.com/topic/87493-loop-and-display-data-help/#findComment-447534 Share on other sites More sharing options...
ShaolinF Posted January 24, 2008 Author Share Posted January 24, 2008 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/87493-loop-and-display-data-help/#findComment-447575 Share on other sites More sharing options...
mmarif4u Posted January 24, 2008 Share Posted January 24, 2008 Use javascript or Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/87493-loop-and-display-data-help/#findComment-447579 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.