have my doubts. What are you using now? Have you tried it with a query that returns at least one row?
EDIT:
Ah, a test reveals that MySQL5 at least returns the number of rows selected when mysql_affected_rows() is called. On the other hand, I would caution that there is no guarantee that you will actually get the number of rows selected. Read the PHP manual on mysql_affected_rows() and PDOStatement's rowCount() for more details.
Hi,
i previously used this code
$query="select date from view_diary";
$result=mysql_query($query);
$num_rows=mysql_num_rows(); // execution stopped here will not go to the next line of code (i.e wont return from the function "mysql_num_rows")
this is the case when there are no rows in the table. (I had thought it would return a zero.)
when i checked the doumentation of mysql_num_rows, i learned that it will eiter return number of rows, or a flase on failure.
maybe it treats a zero- rows(nothing to return) as a failure even though it could have returned a 0
then i used this code
$query="select date from view_diary";
$result=mysql_query($query);
$num_rows=mysql_affected_rows();
if($num_rows==0)
{$j=0;}
else{
for($k=0;$k< $num_rows;++$k)
{
$array=mysql_fetch_row($result);
if($array[0]==$date)
{
++$j;
}
}
}
this code is to check if the value of $date is already present in the table.(and if not present, add it to the table) i used a for loop to seach through the table values.(this is where i needed the number of rows). but in the case of an empty table, the code does not run, as it halts at the line where number of rows are found out!.
Do tell me if there is an easier way of doing this same operation.
Thank you.