Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help with database Queries in HTML tables

    Hi,

    I having problems displaying queries from a mySQL database. I want to display images and descriptions in a html table four columns wide.

    so far I cam up with this.

    PHP Code:
    while ($row mysql_fetch_array$result )){
    $entry_name $row['entry_name'];
    $entry_submition $row['entry_filename'];
    $entry_pic '<div class="display-img"> <img src="../photos/'.$row['entry_filename'].'"></div>';
    $count=4;
    echo 
    "<table>";
      
       echo 
    '<tr>';
       for (
    $counter=0$counter <$count$counter++){
            echo 
    '<td>'.$entry_name.'<br>'.$entry_pic.'<td>';
       } 
      echo 
    '</tr>';
    echo 
    "</table>";

    This displays the table correctly, but it shows each item four times in each row.

    What I need it to show each item once.

    If any one can help. That would be great

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    PHP Code:
    $count 0;
    echo 
    "<table>\n";
    while (
    $row mysql_fetch_array$result ))
    {
        if ( 
    $count == ) { echo "<tr>\n"; }
        
    $entry_name $row['entry_name'];
        
    $entry_submition $row['entry_filename'];
        
    $entry_pic '<div class="display-img"> <img src="../photos/'.$row['entry_filename'].'"></div>';

        echo 
    '<td>'.$entry_name.'<br>'.$entry_pic.'<td>\n';

        ++
    $count;
        if ( 
    $count == 
        {
            echo 
    "</tr>\n";
            
    $count 0;
        }
    }
    echo 
    "</table>\n"
    Untested. I don't use PHP. But I use this technique with other languages and it works.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •