Jump to content

Listing Information from a database


jimmyelewis

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.
Link to comment
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]
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.