[thelist] php output

Mark Groen markgroen at gmail.com
Sun Sep 19 14:21:45 CDT 2004


Thanks, makes more sense now, what a great list - got two ways to do it :-)

cheers,

       Mark

> All you need to do is add a counter variable that counts the number of
> times the while loop has iterated.
> 
> Then, every time that count is divisible by four (i.e., after 4 records
> have been displayed) or some other arbitrary number, you would output
> the link to return to the top of the page.
> 
> This is done using the modulo operator, %, which evaluates to the
> remainder (the modulus) of the first operand divided by the second.

$i = 0;
$to_top_after = 5; // number of rows
while (...)
   ...
   if ( ($i % $to_top_after) == ($to_top_after - 1) ) {
       echo '<a href="#top">Back to top</a>';
   }
   ++$i;
}

... or some such
> 
> <?php
> // initialize the $i variable to 0:
> $i = 0;
> 
> while ($row = mysql_fetch_row($mysql_result)) {
> 
>      // do all of your output and such here
> 
>      // increment the counter:
>      $i++;
> 
>      // check to see if the counter is divisible by 4:
>      if ($i % 4 == 0) {
>          // output your "to the top" link here
>      }
> }
> ?>
> 
> Hope the helps,
> David Bindel
> 



--


More information about the thelist mailing list