Suraj Hazarika
Suraj Hazarika

Reputation: 667

mysql_num_rows returns 1

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

Answers (4)

user825884
user825884

Reputation: 16

Check using phpmyadmin, how many rows have group id = 6.

Upvotes: 0

Rush
Rush

Reputation: 715

You can search for group_id = 6 in phpmyadmin in search tab. you can check for 6 in group_id.

Upvotes: 0

nfechner
nfechner

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

Nahydrin
Nahydrin

Reputation: 13507

You have 1 record stored in tbl_group where group_id = '6'.

Upvotes: 1

Related Questions