How to show the pics ?

images php coding issues or problems here.

Moderators: macek, egami, gesf

cliffcc
New php-forum User
New php-forum User
Posts: 26
Joined: Sat Nov 13, 2010 2:32 am

How to show the pics ?

Postby cliffcc » Wed Jan 26, 2011 7:16 am

How can i show the pics in this way?

---------------------------------------

Pic 1 Pic 2 Pic 3 Pic 4 Pic 5 |
Pic 6 Pic 7 Pic 8 Pic 9 Pic 10 |
Pic 11 Pic 12 Pic 13 Pic 14 Pic 15 |
|
|
------------------------------ ------ |



But below code only show:

---------------------------------------

Pic 1 |
Pic 2 |
Pic 3 |
Pic 4 |
Pic 5 |
Pic 6 |
Pic 7 |
Pic 8 |
Pic 9 |
Pic 10 |
------------------------------ ------ |

Code: Select all

<?php
       
         $album = mysql_query("SELECT * FROM albums WHERE id='$id'");

         echo "<table width='50%'>";

         while ($row = mysql_fetch_assoc($album))

         {
          echo "
          <tr>
            <td>         
            <img src='".$row['pic']."' width='100' height='100' border='0'>     
            </td>       
           </tr>
         ";
         }
         echo "<table>";


?>

User avatar
Lecisco
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Jan 29, 2011 10:34 am
Contact:

Re: How to show the pics ?

Postby Lecisco » Sat Jan 29, 2011 6:07 pm

Your code puts out one row per picture (each row is surrounded by <tr>...</tr>). To get 5 per row you would need code like this:

Code: Select all

echo "<table width='50%'>";
$count = 0;
while ($row = mysql_fetch_assoc($album))
{
    if ($count % 5 == 0) {    // every 5 entries, put start a new row
        if ($count != 0)
            echo "</tr>";  // end the previous row
        echo "<tr>";  // start a new row
    }
    echo "
            <td>         
            <img src='".$row['pic']."' width='100' height='100' border='0'>     
            </td>";
    $count ++;  // add one to the count
}  // end while
if ($count > 0) echo "</tr>";  // end the row that was in progress
echo "</table>"; // end table


Return to “PHP coding => Images”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest