Reputation: 667
Why does the code below returns 1 although there is no elements in the field group_members ?
$conn = mysql_connect($host,$user,$pass);
@mysql_select_db($db);
$sql = "
SELECT
group_members
FROM
tbl_group
WHERE
group_id = '6'
";
$res = mysql_query($sql);
$rows = mysql_num_rows($res);
echo $rows;
?>
Upvotes: 1
Views: 519
Reputation: 715
You can search for group_id = 6
in phpmyadmin in search tab. you can check for 6 in group_id
.
Upvotes: 0
Reputation: 17525
The SQL you wrote will select all rows with group_id = 6
and then return the value of the field group_members
regardless the content. To get what you want, try:
SELECT group_members FROM tbl_group WHERE group_id = 6 AND group_members <> '' // Depending on type might also be <> NULL or <> 0
Upvotes: 3