Jump to content

[SOLVED] 3 images per row


SkyWalker

Recommended Posts

hi...!I m new in php.i want some help in my code..plz..

i have an images in mysql table .and i want to retreive them in such a mannar.."3 images per row"

 

..how can i make it possible..

the code is given below..!

================

<?php

include "dbconfig.php";

?>

 

<link href="main.css" rel="stylesheet" type="text/css" />

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#BCC5C7">

 

<tr><?php

$results = "SELECT * FROM files WHERE menu_item_id='5' limit 12";

$Img_result = mysql_query ($results, $conn);

if (mysql_num_rows ($Img_result) >= 0){

$Img_menu = array();

while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)){

 

$realname = $rows ['filename'];

$small_preview = 'download/wallpapers/'.$realname.'';

$large_preview = 'download/wallpapers/'.$realname.'';

 

?><td><?php echo "<a href='$large_preview' target='_blank'><img width='120' height='200' src='$small_preview' border='0'></a>";?>

<br /><div class="pic"><strong>Name :</strong> <?php echo $rows ['title']; ?></div></td><? } } ?></tr>

 

</table>

Link to comment
https://forums.phpfreaks.com/topic/139460-solved-3-images-per-row/
Share on other sites

here you go !!!

 

 

<?php
include "dbconfig.php";

$results = "SELECT * FROM files WHERE menu_item_id='5' limit 12";
$Img_result = mysql_query ($results, $conn);
if (mysql_num_rows ($Img_result) >= 0){
$Img_menu = array();
while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)){

?>
<table> //making a table
<tr> // first row
<?php 
$i = 0; //initialize loop counter 
    do{
$realname = $rows ['filename'];
$small_preview = 'download/wallpapers/'.$realname.'';
$large_preview = 'download/wallpapers/'.$realname.'';
if ($i >3){
   echo "<tr>"; // if our loop reached 3 columns then we make another row
}
?>
     <td> <!-- columns start-->
          <?php echo "<a href='$large_preview' target='_blank'><img width='120' height='200' src='$small_preview' border='0'></a>";?><br>
          <div class="pic"><strong>Name :</strong> <?php echo $rows ['title']; ?></div>
      </td> <!-- columns end -->
<?php
     ++$i;
     if($i>2){
        echo "</tr>"; // If loop reached 3 columns we stop the row.
       $i = 0; // we make counter 0 to to make sure we will have another TR 
     }
} while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)); 
?>
</tr>
</table>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.