Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi when i run a rowCount() it gives me a seperate count, how can i do count for EVERYTHING thats displayed?
For example, the while loop is looping through lots of 'words' and displaying necessary information regarding this, when i do rowCount, it will print the row count for that particular word on each item displaying

What i want is to have a rowCount of HOW many items are being displayed?

This is how its displaying:

ITEM 1 | - information | & then row count of word in DB e.g 3
ITEM 2 | - information | & then row count of word in DB e.g 2

What I have tried:

while($dbRow=$dbQuery->fetch(PDO::FETCH_ASSOC))  
    {
		   echo $dbQuery->rowCount()."\n"; // ROW COUNT
            echo "".$dbRow["Name"].""."<br><img src=Breakfast/".$dbRow['
Picture']."' width='150' height='150' />"."".$dbRow["Instructions"]."<input type='submit' name='submit' value='Completed' class='button-recipe'>";
 }
	}
Posted
Updated 30-Mar-18 4:28am
Comments
Richard MacCutchan 30-Mar-18 4:50am    
Your question is not clear; exactly what are you trying to count?
Member 13637584 30-Mar-18 15:05pm    
Hi, i want a count of how many actual rows are being displayed?
Richard MacCutchan 31-Mar-18 3:48am    
Being displayed where?

1 solution

If you need to count in a do, while, or foreach loop, you need your own counter.

More than likely, you'll need the results of the count outside of the loop, so it must have a scope outside the loop. In general, then, you count as follows:
PHP
int i = 0;  // this is your counter
aLoop {
 // do what you need to do, then
  i++;   // count what you need to count;
 // continue with your loop or leave it.
} // end of aLoop
As you go through such a loop, you can count more than one thing. How should be obvious to you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900