Jump to content

Populating a drop down box from values in databases - HELP


oliverj777

Recommended Posts

Basically,

 

I have a database table called 'users' and I would like to populate a drop down box with these values of 'users'.

 

How?? - to call upon the values is this: 'upduser2'

 

Right now, all I am using is a text box, in where you have to type in the users name manually (this is so an admin can change variables and settings according to that current user). This is what I am using so far:

 

 

<h3>Update User Level</h3>
                                                    <? echo $form->error("upduser"); ?>
                                                    <table>
                                                      <form action="adminprocess.php" method="post">
                                                        <tr>
                                                          <td> Username:<br />
                    <input type="text" name="upduser" maxlength="30" value="<? echo $form->value("upduser"); ?>" /></td>
                                                          <td> Level:<br />
                                                          <select name="updlevel">
                                                              <option value="1">1 </option> //example settings
                                                              <option value="9">9 </option>
                                                            </select></td>
                                                          <td><br />
                                                            <input type="hidden" name="subupdlevel" value="1" />
                                                            <input type="submit" value="Update Level" /></td>
                                                        </tr>
                                                      </form>
                                                    </table></td>
                                                </tr>

 

 

Much help would be appreciated.

Link to comment
Share on other sites

Say your database is called "USERS" and you have fields like "username", you can populate the dropdown list with the values of "username" as follows:

<?php
$result = mysqli_query($link, 'SELECT * FROM users');        
while ($row = mysqli_fetch_array($result))  { $users[] = array('username' => $row['username']); } 
?>
<form>
<select name="users">
<?php foreach ($users as $user):  ?>
<option value="<?php echo $user['username']; ?>"> <?php echo $user['username']; ?></option>
<?php endforeach; ?>
</select>
<form>

 

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.