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>';

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>';

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.