Count the number of rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jm00730
Forum Newbie
Posts: 13
Joined: Tue Feb 01, 2011 1:32 pm

Count the number of rows

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Count the number of rows

Post 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>';
}
Post Reply