Re: Automatic Table Creation
| From: | Jonathan Pitcher | Date: | Mon, 03 Mar 2003 16:17:12 +0000 |
| Subject: | Re: Automatic Table Creation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-137906@lists.php.net to get a copy of this message | ||
Awlad,
I would guess you are trying to create an HTML table to display the records.
$Row = The results returned from. mysql_fetch_array().
$Total = count($Row);
$TotalInEachRow = round(($Total/3));
if (($TotalInEachRow * 3) < $Total) {
$TotalInEachRow ++; // Planning for the Remainder items.
}
$HTML = "<TABLE>"; // HTML string that holds the table
$ColumnCount = 0; // For knowing the Number of Columns.
for ($C=0; $C<$Total; $C++) {
if ($ColumnCount == 0) {
$HTML .= "<TR>";
}
$HTML .= "<TD>".$Row[$C]["DatabaseFeildName"]."</TD>":
$ColumnCount ++;
if ($ColumnCount == 3) {
$HTML ."</TR>";
$ColumnCount = 0;
}
}
if ($ColumnCount > 0) {
for ($C=$ColumnCount; $C<=3; $C++) {
$HTML .= "<TD> </TD>";
}
$HTML .= "</TR>";
}
$HTML .= "</TABLE>":
That should do it for you. I typed this code directly into the email so be forwarned about copy and pasting it.
Hope this helped.
Jonathan Pitcher
On Monday, March 3, 2003, at 08:58 AM, Awlad Hussain wrote:
I have a mysql table containing about 100 record, alphabetically ordered. How would i display them in browser in a 3 columns, doesn't matter how long the rows is as the number of records will grow in the database table. the records should be in alphabetically order, for example:aaa bbba ccca aab bbbb cccb aac bbbc cccc aad bbbd cccdany idea anyone? awlad _______________________________________________________________________ Sheridan Phoenix Company The Business Centre Kimpton Road Luton Bedfordshire LU2 0LBEmail: a.hussain@sheridan-phoenix.com Phone: 01582 522 330 Fax: 01582 522 328_______________________________________________________________________ This electronic transmission is strictly confidential and intended solely for the addressee. If you are not the intended addressee, you must not disclose, copy or take any action in reliance of this transmission. If you have received this transmission in error it would be helpful if you could notify The Sheridan Phoenix Company Ltd as soon as possible. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of The Sheridan Phoenix Company Ltd.