Well I guess I'd better get my 2 cents in.  :)   There is a natural
progression to HTML tables so why fight it?  I think the cleanest way to do
this would be to reorder the array instead of trying to come up with a
clever way to build the table.  Set the number of table rows you want then
use that as an offset to the dates array.  Simply ask
if(isset($dates[$i+$rowoffset]))..  five lines of code in a for() loop and
you got it licked.  Then you can run through the new array and generate the
HTML table linearly without any tricks and pad with the necessary number of
cells.
-Kevin

----- Original Message -----
From: "Jason Soza" <[EMAIL PROTECTED]>
To: "Michael Davey" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, July 11, 2002 3:43 PM
Subject: Re: [PHP] Re: Table Making


> I really wish I was at home right now so I could test this out... I'll
> certainly give this a shot tonight. Taking someone else's earlier
> suggestion and tweaking it a bit, I was wondering if the following
> might work:
>
> $cells = 10; //set desired number of cells per column
> $numRows = mysql_num_rows($result); //determine number of rows
> $numCols = ceil($numRows/$cells); //determine number of columns needed
>
> print "<center><table width=\"100%\" border=\"0\" cellpadding=\"0\"
> cellspacing=\"0\">\n"; //start main table
>
> for($i=0; $i<$numCols; $i++) {
>
> echo "<tr><td align=\"center\">\n"; //setup main row/cell
>
> echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0
> \">\n"; //setup secondary table
>
> while($dataArray = mysql_fetch_array($result)) { //print
> results of SQL in secondary table
> extract($dataArray);
> $n++;
>
> printf("<tr>\n<td align=\"center\" valign=\"center\"><a
> href=\"year.asp?year=%\">%s</td>\n</tr>", $grad_year, $grad_year);
>
> if ($n==$cols) {
> echo "</table>"\n; //close secondary table at
> 10 cells
> }
>
> echo "</td></tr>\n"; //close main row/cell
>
> }
>
> echo "</table>\n"; //close main table
>
>
> Jason Soza
>
> ----- Original Message -----
> From: "Michael Davey" <[EMAIL PROTECTED]>
> Date: Thursday, July 11, 2002 12:01 pm
> Subject: [PHP] Re: Table Making
>
> > How about working out the length of the column (by dividing the
> > number of
> > rows by the number of cols you want), dump your results into an
> > array and
> > using the col length as an offset to pick through the resulting table?
> >
> > // $data is an array of results
> >
> > $rows = count ($data)
> > $row_len = round ($rows / 3); // three cols
> >
> > print "<table>";
> > for ($i = 0; $i < $row_len; $i++)
> > {
> >    print "<tr>";
> >    print "<td>".$data[$i]."</td>";
> >    print "<td>".($row_len + $i < $rows)?$data[$row_len +
> > $i]:" "."</td>";
> >    print "<td>".((2 * $row_len) + $i < $rows)?$data[(2 *
> > $row_len) +
> > $i]:" "."</td>";
> >    print "</tr>"
> > }
> > print "</table>";
> >
> > This is off the cuff code and I think the row length's might need
> > some extra
> > checking, but sth like this should work... (crosses fingers)
> >
> > Mikey
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to