Jump to content

while loop list in 3 columns.


seany123

Recommended Posts

Maybe I misunderstood, but anyway..

$i = 1;
while ($query_result = mysql_fetch_array($query)) {
    echo "1";
    if ($i%3 === 0)
    echo "<br/>";  
    $i++; 
}

 

or maybe this helps..

 

echo '<table border="1"><tr>';
$i = 1;
while ($i < 20) {
echo '<td>'. $i .'</td>';
    if ($i%3 === 0) { echo "</tr><tr>"; }
    $i++;
}
echo '</tr></table>';

How would you like that? with just text and spaces, or with an html table?

 

(what fields does $query_result return?)

 

preferably inside html table but im not too fussed,

 

i currently have something like this... but i dont know how to to <tr>

 

$i = 1;
    <html>
        <table>
            <td id="1"></td>
            <td id="2"></td>
            <td id="3"></td>
    
<?php
while ($query_result = mysql_fetch_array($query)) {
    echo $i;
    ?>
    <td id="<?=$i?>">
    <?php
    echo $i;
    echo "<br/>"; 
    echo "</td>";  
    $i++;
    
    if ($i >= 4){
        $i = 1;
    }  
}
?>
</table>

 

Was doing sort of the same, but TeNDoLLA beat me to it.

I prefer to grab the database stuff firts, and then loop through it and add formatting or whatever. (you need to add the database fields)

 

<?php

$results = array();

while ($query_result = mysql_fetch_array($query)) {

    $results[] = $query_result;

}

$count = 0;

echo '<table><tr>';

foreach ($results as $val){

$count++;

if($count % 3 === 0) echo '</tr><tr>';

echo '<td nowrap="nowrap">'.$val.'</td>';

}

echo '</tr></table>';

?>

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.