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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.