php-db | 2001072
Date: 07/25/01
- Next message: Chris Hobbs: "Re: [PHP-DB] Re: Making a new row in HTML tables"
- Previous message: Matthew Loff: "RE: [PHP-DB] WHERE field = str"
- In reply to: Ian Grant: "[PHP-DB] Re: Making a new row in HTML tables"
- Next in thread: Chris Hobbs: "Re: [PHP-DB] Re: Making a new row in HTML tables"
- Reply: Chris Hobbs: "Re: [PHP-DB] Re: Making a new row in HTML tables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hmmm. No code, but I'm guessing you'll probably want to set the width of
the table to be int(sqrt(mysql_num_rows($results))), and then set up
your loops to place only that amount of cells across. Then just keep
going til you run out of data.
So in the example of 31, you'd set the number of columns to be 5
(int(sqrt(31))), and then create a nested loop to go through your data.
Hmmm. Maybe I will write some code... :)
$numdata = mysql_num_rows($results);
$cols = int(sqrt($numdata));
// This figures out how many
$rows = $cols + ceil(($numdata-($cols*$cols))/$cols);
echo "<table>";
for ($i=1; $i<=$rows; $i++) {
echo "<tr>";
for ($j=1; $j<=$cols; $j++) {
echo "<td>";
$row = mysql_fetch_array($results);
echo $row['name'];
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
Not tested, but I bet it works :)
Ian Grant wrote:
>
> Yeah, but if I had 31,
> I'd want 6x5 and then 1 over, or something....
>
> Hugh Bothwell <hugh_bothwell <email protected>> wrote in message
> news:20010725161627.68874.qmail <email protected>
> > Umm... 31 entries, 1 x 31...
> >
> > You might be better to choose a standard width and pad the last row with
> > empty cells.
> >
> > "Ian Grant" <ian.grant <email protected>> wrote in message
> > news:20010725154701.44170.qmail <email protected>
> > > Hi,
> > >
> > > Can anyone help me with this - I have a database of people, that I want
> to
> > > print into an HTML table - how can I make the table wrap into an equal
> > > number of rows.
> > > i.e. if there are 4 entries, a 2x2 table, 6 a 2x3, 8 a 2x4, 9 a 3x3,
> etc.
> >
> >
> >
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe <email protected>
> For additional commands, e-mail: php-db-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>
-- Chris Hobbs Silver Valley Unified School District Head geek: Technology Services Coordinator webmaster: http://www.silvervalley.k12.ca.us/~chobbs/ postmaster: chobbs <email protected>-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Chris Hobbs: "Re: [PHP-DB] Re: Making a new row in HTML tables"
- Previous message: Matthew Loff: "RE: [PHP-DB] WHERE field = str"
- In reply to: Ian Grant: "[PHP-DB] Re: Making a new row in HTML tables"
- Next in thread: Chris Hobbs: "Re: [PHP-DB] Re: Making a new row in HTML tables"
- Reply: Chris Hobbs: "Re: [PHP-DB] Re: Making a new row in HTML tables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

