Jump to content

[SOLVED] inserting users from a database into a drop down


stelthius

Recommended Posts

Hello guys,

 

Im just wondering how would one go about adding all the users in the database into a drop down menu, the reason for this is i have a ban user function but instead of trying to remember the name you cab just click the drop down menu and select the name to ban,

 

 

Rick

Hi

 

I think something like this would do it:

 

<select name="ID">
            <?php
                 $query = "QUERY HERE";
                 $rs = mysql_query($query);
                 while ($row = mysql_fetch_array($rs))
                 {
                     echo "<option value='$row[0]'>$row[1]</option>";
                 }
            ?>
</select>

 

Hope this helps

 

 

 

 

Tom

Hello again,

 

Im not quite sure were im going wrnog but i tried this

 


<?
include("include/session.php");
?>

<select name="ID">
            <?php
                 $query = "SELECT * FROM `users` WHERE 1 = `username`";
                 $rs = mysql_query($query);
                 while ($row = mysql_fetch_array($rs))
                 {
                     echo "<option value='$row[0]'>$row[1]</option>";
                 }
            ?>
</select>

 

 

And it doesnt seem to be working, the other methods i have tried just show the md5 passwords lol im new to it so im not exactly sure what else to try with it

Try this if you want username displayed on drop down and id as value posted:

 

<?
include("include/session.php");
?>

<select name="ID">
            <?php
                 $query = "SELECT id,username FROM users";
                 $rs = mysql_query($query);
                 while ($row = mysql_fetch_assoc($rs))
                 {
                     echo "<option value='",$row['id'],"'>",$row['username'],"</option>";
                 }
            ?>
</select>

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.