Jump to content

echoing out a while in a table


graham23s

Recommended Posts

Hi Guys,

 

i use this while loop to echout all my categories at once, but is there a way i could have them echo out in a table say 5 across at a time?

 

        ## cat browse ###################################################################
        $query_browse = mysql_query('SELECT `id`, `name` FROM `categories` ORDER BY `name` ASC');

            while ($category = mysql_fetch_assoc($query_browse)) {
            
            $cat_id_gif = $category['id'];
            
            echo '<a href="browse_files.php?cat_id='.$category['id'].'">'.$category['name'].'</a> <b>|</b> ';
            
            
        }
        ## cat browse ###################################################################

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/57981-echoing-out-a-while-in-a-table/
Share on other sites

Try this out:

 

<?php

$query_browse = mysql_query('SELECT `id`, `name` FROM `categories` ORDER BY `name` ASC');

$count = 1;
echo '<table cellpadding=7>';

    while ($category = mysql_fetch_assoc($query_browse)) {
            
        $cat_id_gif = $category['id'];
        
            if ($count == 5){ 
                echo '<tr>';
                $count = 0;
            }
        
        echo '<td><a href="browse_files.php?cat_id='.$category['id'].'">'.$category['name'].'</a></td>';
            
    $count++;        
    }
echo '</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.