Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
Thread: Display MySQL Data In A Form
10-26-2006, 10:30 PM #1
Display MySQL Data In A Form
I am having some trouble with using the MySQL "SELECT" statement to retrieve one COLUMN of data and then placing it into a select form input....
My current syntax is below but I am not sure how I would insert the variables into the form once I select them from the database.... ps. a loop statement would be nice to repeatedly select until there is nothing left...
<?php $result = mysql_query("SELECT username FROM users"); echo "<option>"; echo ""; echo "</option>"; ?>
10-26-2006, 10:47 PM #2
- Join Date
- Sep 2004
- Thanked 40 Times in 40 Posts
Loop the results with mysql_fetch_assoc();
$result = mysql_query("SELECT username FROM users");
echo '<select name="users">';
while($row = mysql_fetch_assoc($result))
echo '<option value="' . $row['username'] . '">' . $row['username'] . '</option>';
10-27-2006, 01:26 PM #3
wow! thanks - works like a charm... but what would I need to add to have the "select" options show in alphabetical order by username?
10-27-2006, 02:16 PM #4
- Join Date
- Jan 2006
- Preston, Lancashire, England
- Thanked 0 Times in 0 Posts
$result = mysql_query("SELECT username FROM users ORDER BY username ASC");