Page 1 of 1

trying to get 2 rows from MYSQL

Posted: Fri May 06, 2005 3:51 pm
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

Posted: Fri May 06, 2005 5:17 pm
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".