> Would someone be kind enough to explain why I'm not getting the correct
> result from the following query.  If I select a valid member no. and name,
> the following query should return 1 row.  This is not the case, however.  It
> returns zero rows.
> 
> $sql = "SELECT  * FROM users WHERE member_no = '$member_no' and
> name = ' $name' ";

Because ' $name' != '$name' so zero rows are returned. So
remove the leading space from your query and you'll get
one row..

> $result = mysql_query($sql) or die ("Cannot verify the member");
> $rows = mysql_num_rows($result);
> echo "rows = $rows<br>";
> 
> Furthermore when trying the following query where the table "users" contains
> 13 rows, the query returns only 12 rows.
> 
> $sql = "SELECT  * FROM users";
> $result = mysql_query($sql) or die ("Cannot verify the member");
> $rows = mysql_num_rows($result);
> echo "rows = $rows<br>";

Because there are 12 rows, not 13 ;)  Check again or simply 
test it:

$sql = "SELECT * FROM users";
if (!$result = mysql_query($sql)) {
    echo "Could not run query ($sql) " . mysql_error();
    exit;
}

$count = mysql_num_rows($result);

while ($row = mysql_fetch_assoc($result)) {
    $rows[] = $row;
}

print "<pre>";
print "Returned: " . count($rows) . " and num_rows: $count\n";
print_r($rows);

> Conclusion: mysql_num_rows seems to be returning one less row 
> than exists.  Is this correct?

Nope.



Regards,
Philip Olson


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to