| View previous topic :: View next topic |
| Author |
Message |
Localhost I post too much
Reputation: 0
Joined: 28 Apr 2007 Posts: 3402
|
Posted: Sat May 10, 2008 10:21 am Post subject: [PHP] A drop down menu with MySQL data? |
|
|
Okay... so i need to make this
| Code: | | echo "Send to: <br><input type='text' name='to'>"; |
To be changed into a drop menu... and the information in the drop down menu would be information from
database: log
table: usr
Thanks
_________________
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sat May 10, 2008 10:39 am Post subject: |
|
|
| Code: | <html>
<select name="top5">
<?php
$res = mysql_query("SELECT name FROM user ORDER BY name ASC");
if(mysql_num_rows($res)){
while($row = mysql_fetch_assoc($res)) {
?>
<option><?php echo $row['name']; ?></option>
<?php
}
}
?>
</select>
</html> |
(The field name of what you need in name here. And it arrangs it in alphabetical order)
|
|
| Back to top |
|
 |
Localhost I post too much
Reputation: 0
Joined: 28 Apr 2007 Posts: 3402
|
Posted: Sat May 10, 2008 11:24 am Post subject: |
|
|
Okay thanks. That works, but how will that effect me getting what they selected via the POST method
| Code: | | $sendto = trim(mysql_real_escape_string($_POST["to"])); |
This is wat i have so far
| Code: | <html>
<select>
<?php
$con = mysql_connect("localhost","3434","45345");
mysql_select_db("login", $con);
$result = mysql_query("SELECT * FROM users", $con);
while($row = mysql_fetch_array($result))
{
?>
Send to: <option><?php echo $row['username']; ?></option>
<?php
}
?>
<form action="send.php" method="POST">
<br>
Subject: <br><input type="text" name="sub">
<br>
Your Message: <br><textarea name="msg" rows="10" cols="45"></textarea><br>
<input type="submit" value="Send">
</form>
<?php
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br><br/>";
?>
</select>
</html> |
Below is a picture of what is showing up
For some reason, ¨Subject¨ is not showing up, drop down menu doesnt have a value, but besides that its what i want
_________________
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sat May 10, 2008 11:55 am Post subject: |
|
|
| Do the select-menu in your form and give it a name.
|
|
| Back to top |
|
 |
|