max_w1 Posted May 19, 2008 Share Posted May 19, 2008 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 https://forums.phpfreaks.com/topic/106325-displaying-images-form-database/ Share on other sites More sharing options...
DeanWhitehouse Posted May 19, 2008 Share Posted May 19, 2008 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 https://forums.phpfreaks.com/topic/106325-displaying-images-form-database/#findComment-544902 Share on other sites More sharing options...
corbin Posted May 19, 2008 Share Posted May 19, 2008 Blade, I don't think that will work. Once you set $loop to 0 the first time, it's never incremented at a later time.... Link to comment https://forums.phpfreaks.com/topic/106325-displaying-images-form-database/#findComment-544908 Share on other sites More sharing options...
DeanWhitehouse Posted May 19, 2008 Share Posted May 19, 2008 this works for me, although i only have the first line with stuff in Link to comment https://forums.phpfreaks.com/topic/106325-displaying-images-form-database/#findComment-544912 Share on other sites More sharing options...
aaronson Posted May 19, 2008 Share Posted May 19, 2008 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 https://forums.phpfreaks.com/topic/106325-displaying-images-form-database/#findComment-544935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.