--- Joseph <[EMAIL PROTECTED]> wrote:

> I am trying create a table on the fly, to display unicode characters
> and I want that every thirty table cells to insert a table header cell
> so that when a user scrolls down the page they can always see a header
> every so often.
> 
> Can anyone point me to a good mathematics tutorial for PHP please?
> 
> Joseph 

This specific application is a good job for the modulus operator (%) which
basically returns the remainder of division.  For example, if you wanted to
have alternating shading you could do something like:

printf("<tr bgcolor='%s'>", ($row++ % 2) ? "#cccccc" : "#ffffff");

In this example, a variable $row is incremented after the expression is
evaluated.  The expression will take $row and divide by 2 and return the
remainder (either 0 if even or 1 if odd).

The conditional operator is used here to insert one value if the expression is
true and another value if false:

(condition) ? value_if_true : value_if_false

In your case, you'd want to use modulus 30 and show the header row if the
remainder value is 0:

print ($row++ % 30) ? "" : $header;

Print nothing if the remainder is non-zero (ie "true") and the contents of
$header if the remainder is zero (ie false).

There are other variations but this one works well for me in most situations.

James

Reply via email to