PHP MYSQL REPEATER WITH COUNTER

Hello, I need to arrange the results of a mysql query into divs which require 2 counters:

Assuming the results are 9 rows containing fields title, image content...

Select * FROM tblcontent ORDER BY Ordinal ASC...

While ($row =.....)
{


}...

I need a arrange the results into page and column divs as follows:

div=Page1
   div=column1... fields title, image content...
   div=column2... fields title, image content...
   div=column3... fields title, image content...
div=Page2
   div=column1... fields title, image content...
   div=column2... fields title, image content...
   div=column3... fields title, image content...
div=Page3
   div=column1... fields title, image content...
   div=column2... fields title, image content...
   div=column3... fields title, image content...

So basically counter 'column' runs 1-3 and loops back after 3, counter page increments after every counter column loop.

There will always be 1 page div and 1 column, but there maybe, 2 columns or in the case of 4 columns that would be 2 pages.

I'm new to php so appreciate as much detail as possible.
Thanks.
repeats after
onetoomanyAsked:
Who is Participating?
 
hieloCommented:
assuming your result set has a field named 'id':
$i=0;
		$page=1;
		$groupCount=3;
		echo ("<div id='page".$page."'>")
		while( $row = mysql_fetch_assoc($result) )
		{

			
			echo("<div>".$row['id']."</div>");
			$i= (++$i % $groupCount);		
			if(!$i)
			{
				++$page;
				echo("</div><div id='page".$page."'>");
			}
		}

		echo("</div>");

Open in new window

0
 
onetoomanyAuthor Commented:
Thanks Hielo! Worked.

a couple of questions:

echo ("")

Has to be wrapped in parenthesis? Has to be in double quotes? Are there any other methods to write this?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.