display images in a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lesh
    New Member
    • May 2012
    • 5

    display images in a table

    i am tryn to display images from a folder and details from the database but the images display in a row not in a column as i want thm to be.please experts help me
    below is the code
    Code:
    <?php
    $conn= mysql_connect("localhost","root","lesego");
    if(!$conn)
    {
     die('Could not connect: ' .mysql_error()); 
    }
    mysql_select_db("exhibition", $conn);
    $path='livestock/';
    $dir_handle = @opendir($path) or die("Unable to open folder");
    $result= mysql_query ("SELECT * from livestock"); 
    if($result){
    echo '';
    }
    else{
    echo"Invalid query: " . mysql_error();
    }
    echo "<table border='1'>";
    echo "<tr><th>bid</th><th>breed</th><th>colour</th><th>dob</th><th>photo</th>";
    while($row=mysql_fetch_array($result))
    {//prints out the contents of each row into a table
    echo"<tr><td>";
    echo $row['bid'];
    echo"</td><td>";
    echo $row['breed'];
    echo"</td><td>";
    echo $row['colour'];
    echo"</td><td>";
    echo $row['dob'];
    echo"</td>";
    while (false !== ($file = readdir($dir_handle))) {
    if($file == "index.php")
    continue;
    if($file == ".")
    continue;
    if($file == "..")
    continue;
    echo"<td>";
    echo"<img src='$path/$file' alt='$file' height=100 width=100><br/></td>";
    }
    }
    echo "</tr>";
    echo "</td>";
    echo "</table>";
    mysql_close($conn);
    ?>
    Last edited by Rabbit; May 11 '12, 04:41 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    You forgot to close the row after each image. And you have an extraneous td closing tag at the end.

    Comment

    • Lesh
      New Member
      • May 2012
      • 5

      #3
      i have removed the td closing tag and added the tr closing tag after the code that displays images but only one image is displayed under the photo header then other images line up below bid header.what have i done wrong.im new to php.thanks in advance

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You didn't close your header row.

        Comment

        • Lesh
          New Member
          • May 2012
          • 5

          #5
          now the first row displays just fine then other images line up below the first row and other details are displayed below the images.i dont know what the problem might be

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            I'm not sure what that means, a screenshot would help.

            Comment

            • Lesh
              New Member
              • May 2012
              • 5

              #7
              bid breed colour dob photo
              1 brahman black 12-02-2012 image1(which is fine)
              image2
              image3
              11 brahman black 12-02-2012
              2222 senien brown 13-04-2012

              did not know 2 do this but that is basically what i get.hope you can understand that

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                That's because you're looping through all your pictures at once.

                Comment

                • Lesh
                  New Member
                  • May 2012
                  • 5

                  #9
                  thanks for helping me so far, i am really lost now.i do not know how to display 1 image at a time.i am new to php.what do you suggest i should use?

                  Comment

                  Working...