Page 1 of 1

Count the number of rows

Posted: Wed Feb 09, 2011 3:57 pm
by jm00730
I am trying to runa query which will feed data into a graph however when trying to get the affected rows in the query i am returned with zero when i know for sure there are rows that match the criteria. below is the code:

Basically the search is finding any dates within a date range for a particular body part for the user

Code: Select all

$partQuery = mysql_query("SELECT DateEntered, $part FROM indBody WHERE MemberID = '$id' AND  DateEntered >= DATE_SUB(CURDATE(), INTERVAL '$view' DAY) AND CURDATE()    ORDER BY DateEntered");
			 
$count = mysql_num_rows($partQuery);
			
echo "count is : ". $count;
Is there something wrong with my logic?

Re: Count the number of rows

Posted: Wed Feb 09, 2011 3:59 pm
by John Cartwright
Your logic is right. Run the following code and post the results.

Code: Select all

$partQuery = mysql_query("SELECT DateEntered, $part FROM indBody WHERE MemberID = '$id' AND  DateEntered >= DATE_SUB(CURDATE(), INTERVAL '$view' DAY) AND CURDATE() ORDER BY DateEntered");
                         
$count = mysql_num_rows($partQuery);
                      
echo "Count is : ". $count ."<br />";
while ($row = mysql_fetch_assoc($partQuery)) {
   echo '<pre>'. print_r($row, true) .'</pre>';
}