RE: [PHP] newbie algorithm help!!!!!
| From: | Maamiin | Date: | Sat, 23 Jun 2001 21:45:14 +0000 |
| Subject: | RE: [PHP] newbie algorithm help!!!!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-54993@lists.php.net to get a copy of this message | ||
I use this code to do this kind stuff:
----------------- BEGIN -----------------------
$result=mysql_query(...);
$columns=2; //Count of columns
$table="<TABLE>\n";
$table.='<TR>';
$col=0; //current column
//Draw table content
while ($row=mysql_fetch_row($result)){
$table.='<TD>'.$row[0].'</TD>';
$col++;
if ($col>=$columns) { $table.="</TR>\n<TR>"; $col=0;} // Next row
}
//Correct last row, add or remove empty cells.
if ($col) {
$table.=str_repeat('<TD> </TD>',$columns-$col); //Add empty cells
}else{
$table=substr($table,0,strlen($table)-10); //Remove empty row
}
$table.="</TR>\n";
$table.='</TABLE>';
echo $table;
----------------- END -----------------------
X