Jump to content

Archived

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

rkiss

3 or more multi column resultset

Recommended Posts

Hi,

I am looking for a solution for the following issue:

I am trying to split up my resultset into multiple colums, but I can't find anything that would fit my needs:

Sample Output:

A E I
B F J
C G K
D H L

Does anyone have a solution or know some good tutorial?

Thank You

RK

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.