Jump to content

Displaying Images form database


max_w1

Recommended Posts

hi i have a code that gets images form database and displays it on the page,

but my problem is with the images which are not been displayed in a pattern

_______________________

pattern i am getting now is

_______________________

 

|image1|

 

|image2|

 

|image3|

 

_______________________

Pattern i want is

_______________________

 

|image1|  |image2| |image3|

 

|image4|  |image5| |image6|

 

|image8|  |image9| |image10|

 

pleeeeeese help me, i am in a great problem coz i have to submit the project tmrw.

thankyou in advance

Link to comment
Share on other sites

i think this is what you want

 

Change some parts of it for your needs

 

<?php
               $loop = 3;
		   $loop1 = 3;
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;
               echo $toecho1;
}

?>		

Link to comment
Share on other sites

give this a try, i wrote it to display a neat table grid of data.

 

$max = 3; // change to max columns

 

<?php
  $html = '<table width="100%" border="0" align="center">';
$ex = 'height="30" align="center" valign="middle"';
$imageArray = array("imagelocation", "imagelocation", "imagelocation", "imagelocation", "imagelocation");

$cellCount = count($imageArray);
$max = 3;
$count = 0;
$msg = "";
$i=0;
foreach ($imageArray as $value){
	$count++; $i++;
	$value = "<img src=\"$value\">";
	if ($count==1){ $msg .= "<tr>"; }
		if ($i==($cellCount)&&$count<$max) $msg .= "<td $ex colspan=\"$max\">$value</td>";
		else $msg .= "<td $ex>$value</td>";
	if ($count==$max || $i==($cellCount)){ $msg .= "</tr>"; $count = 0; }
}
$html .= $msg;
$html .= "</table>";
echo $html;
?>

 

update: noticed my colspan was wrong... added $max to the mix

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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