Jump to content

Interrupting long While Loops with heading rows


Aegist

Recommended Posts

I tried searching for this before posting, but I'm not even sure what to search for. Obviously I couldn't find what I was looking for, so hopefully it isn't too stupid a question (I am very noob with PHP still).

 

I have a lot of data that I am pulling from a MySQL DB and displaying it in a crude table. Is there anyway to start the while loop (pulling up say, 80 results), and direct it to print a row of headings every 20 results? So that way the users still know what they are looking at even when scrolled down to the bottom.

 

Or is this the wrong question to ask? ;)

 

Thanks for any help!

Shane

You can do it 2 ways.  Either limit the sql query to 20 results and have multiple queries, or have some sort of counter that increases each time the loop is executed.  When it gets to 20 (or a multiple thereof), include the headings.

 

<?php
$i = 0;
while($array = mysql_fetch_array($query))
{
    if(fmod($i,20) == 0)
    {
        //echo heading
    }
    //echo current line
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.