Jump to content

help


hostfreak

Recommended Posts

What im trying to do is be able to select the agent name which is $username from the table users but have its value be the id_num. Here is what Im doing:

[code]
$query = "SELECT id_num FROM users WHERE userlevel = '8'";  
$result = mysql_query($query);
print "<SELECT name=id_num><option>Choose One</option>";
while ($row = mysql_fetch_array($result))
    {
        extract($row);
        echo  "<option value='$id_num'>$id_num</option>";
    }
    mysql_close($link);
print "</SELECT>";
[/code]

Im not sure how to exactly call the $username. Last time i tried it, it listed the username logged in for all the options. I guess because i didn't call it as a line or something.
Link to comment
https://forums.phpfreaks.com/topic/8086-help/
Share on other sites

[!--quoteo(post=367326:date=Apr 21 2006, 02:27 PM:name=HostFreak)--][div class=\'quotetop\']QUOTE(HostFreak @ Apr 21 2006, 02:27 PM) [snapback]367326[/snapback][/div][div class=\'quotemain\'][!--quotec--]
What im trying to do is be able to select the agent name which is $username from the table users but have its value be the id_num. Here is what Im doing:

[code]
$query = "SELECT id_num FROM users WHERE userlevel = '8'";  
$result = mysql_query($query);
print "<SELECT name=id_num><option>Choose One</option>";
while ($row = mysql_fetch_array($result))
    {
        extract($row);
        echo  "<option value='$id_num'>$id_num</option>";
    }
    mysql_close($link);
print "</SELECT>";
[/code]

Im not sure how to exactly call the $username. Last time i tried it, it listed the username logged in for all the options. I guess because i didn't call it as a line or something.
[/quote]


First off, you can query more than one column in a single query, right?

Try this code instead:

[code]
$query = "SELECT id_num, username FROM users WHERE userlevel = '8'";  
$result = mysql_query($query);
print "<SELECT name=id_num><option>Choose One</option>";
while ($row = mysql_fetch_assoc($result))
    {
        echo  "<option value='{$row['id_num']}'>{$row['username']}</option>";
    }
    mysql_close($link);
print "</SELECT>";
[/code]

Link to comment
https://forums.phpfreaks.com/topic/8086-help/#findComment-29471
Share on other sites

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.