Jump to content

displaying query results horizontally


steveginer

Recommended Posts

[code]<?php

$recordsPerRow = 4;
$currentRecord = 0;
echo "<table>";

while ($record = mysql_fetch_array($results)) {

    if ($currentRecord == 0) {
        echo "<tr>";
    }

    echo "<td>" . $record[field] . "</td>";
    $currenttRecord++;

    if ($currentRecord == $recordsPerRow) {
        echo "</tr>";
        $currentRecord = 0;
    }
}

if ($currentRecord!=0) {
    for ($i = $currentRecord; $i<$recordsPerRow; $i++) {
        echo "<td></td>";
    }
    echo "</tr>";
}

echo "</table>";
?>[code][/code][/code]
thanks so much. just for anyone else who might reuse this code "$currenttRecord" should be $currentRecord in the code reference here.

    echo "<td>" . $record[field] . "</td>";
    $currenttRecord++;

hate to be nag but how would you go about limiting the number of rows displayed per page and then paginate the results. i know this is asking a lot but...

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.