trying to get 2 rows from MYSQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paquin1
Forum Commoner
Posts: 36
Joined: Fri Aug 06, 2004 1:57 pm

trying to get 2 rows from MYSQL

Post by paquin1 »

is this code correct:

Code: Select all

$query = "SELECT concat(u_first_name, ' ', u_last_name) AS name FROM users WHERE u_group=1 AND u_group=2"; 
$result = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<select name=\"submitter\" id=\"submitter\">";
echo "<option value=\"0\" selected>Employee</option>";
while ($row = mysql_fetch_array($result)) {
     printf ("<option value=\"{$row['name']}\">{$row['name']}</option>/n");
}
echo"</select>";
When I do this, no informatin is display, I than remove "AND u_group=2" from $query and it works...
is the code wrong? or how do I get two rows from MySQL?

thanks.

Jcart | Please review :arrow: Posting Code in the Forums
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

SELECT concat(u_first_name, ' ', u_last_name) AS name FROM users WHERE u_group=1 AND u_group=2
A record has to match all the parts of the where clause in a SQL statement. u_group can't be both 1 and 2 at the same time, so it'll never match. You probably want "where u_group=1 OR u_group=2".
Post Reply