Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

List all users in a database in a drop-down menu

$
0
0

Hi.

 

Sorry if I've posted in the wrong forum or something - I joined this forum a few seconds ago. :P

 

I'm trying to create something which displays all of the users in a database table in a drop-down menu. I've tried this code:

<?php

include 'config.php';
session_start();
$suser       = $_SESSION['user'];
$con          =  mysql_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_pass']);
mysql_select_db($config['database']);
$cpuTable = $config['cpuTable'];
$query       = mysql_query("SELECT * FROM $cpuTable WHERE suser='$suser'");

while($row = mysql_fetch_assoc($qa)) {
     $users = $row['username'];
     echo "
              <select name='cpuser'>
              <option value='user'>$users</option>
              </select>";
}

I created two users in the database - "cp_test1" and "cp_test2", tried the code and it outputted this:

 

2w3chht.png

Instead of listing the users in one drop-down menu, it creates two and lists one in each. Can anyone help?

 

Thanks

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles