Jump to content

Archived

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

jimmyelewis

Listing Information from a database

Recommended Posts

What I'm trying to do is list some infomation from mysql into a 3 column table. Here's what I have.

[code]            echo '<div class="title">' . $row['cat_name'] . '</div>';
            $query2 = 'SELECT * FROM admin_tools ORDER BY tool_num ASC';
            if($r=mysql_query($query2)) {
                echo '<table>';
                while ($row2 = mysql_fetch_array($r)) {
                        echo '<tr>';
                        $count=0;
                        while ($count<3){
                        echo '<td>';
                        if($row2['tool_icon']){$a='<a href="' . $row2['tool_link'] . '"><img src="' . $row2['tool_icon'] . '" border="0" /> </a>';}
                        else {$a='&nbsp;';}
                        echo $a . '<a href="' . $row2['tool_link'] . '"><br />' . $row2['tool_name'] . '</a><br /></td>';
                        $count++;
                        }
                        echo '</tr>';
                    }
                        echo '</table';
                }
[/code]


Instead of printing each database entry into a new table cell until it reaches 3 and going to the next table row. It prints the each database entry on a new row and mirrows that column to the next 2. What have I written wrong in my code.

Share this post


Link to post
Share on other sites
$count is always going to be zero according to your code.

[code]echo '<div class="title">' . $row['cat_name'] . '</div>';
            $query2 = 'SELECT * FROM admin_tools ORDER BY tool_num ASC';
            if($r=mysql_query($query2)) {
                echo '<table>';
                $count = 0;
                while ($row2 = mysql_fetch_array($r)) {
                        if($count == 0) {
                             echo '<tr>';
                        }
                        echo '<td>';
                        if($row2['tool_icon']){$a='<a href="' . $row2['tool_link'] . '"><img src="' . $row2['tool_icon'] . '" border="0" /> </a>';}
                        else {$a='&nbsp;';}
                        echo $a . '<a href="' . $row2['tool_link'] . '"><br />' . $row2['tool_name'] . '</a><br /></td>';
                        if(++$count == 3) {
                             echo '</tr>';                            
                             $count = 0;
                        }
                        
                    }
                        echo '</table';
                }[/code]

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.