Jump to content


Photo

Listing Information from a database


  • Please log in to reply
1 reply to this topic

#1 jimmyelewis

jimmyelewis
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 23 March 2006 - 02:46 PM

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

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


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.

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 23 March 2006 - 02:50 PM

$count is always going to be zero according to your 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';
                }

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users