Jump to content

3 or more multi column resultset


rkiss

Recommended Posts

This will give

ABC
DEF
GHI

[code]define ("NUMCOLS",3);

$res = mysql_query("SELECT area, locname FROM baagriddata");

$count = 0;
echo "<TABLE border=1>";
while (list($col1, $col2) = mysql_fetch_row($res)) {

    if ($count % NUMCOLS == 0) echo "<TR>\n";  # new row

    echo "<TD>$col1<br>$col2</TD>\n";
    $count++;

    if ($count % NUMCOLS == 0) echo "</TR>\n";  # end row
}
if ($count % NUMCOLS != 0) {
   # end row if not already ended
   while ($count++ % NUMCOLS) echo "<td>&nbsp;</td>";
   echo "</TR>\n";
}
echo "</TABLE>";[/code]

To do it as you asked will reqire storing tha data into an array , calculating how many rows are needed, R, then outputting record n, n+R, n+2R into each row.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.