imarockstar Posted June 3, 2009 Share Posted June 3, 2009 hey I have this code that displays images ... but it just spits them out ... Is there away to where i can limit the amount of images displayed on each row ... like i need to have it out output : "<br class='clear'>" after a certain number of images .. say 10 .. this is my code : <?php $image_path = 'flyers/'; // Retrieve data from database $sql="SELECT * FROM flyers WHERE uid = ". $_SESSION['id']; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <div class='flyerbox'> <a href="viewimage.php?maxsize=640&source=<?=$image_path.$rows['flyer'] ?>" rel="facebox"> <img src="viewimage.php?maxsize=75&source=<?=$image_path.$rows['flyer'] ?>" /></a> <br> remove </div> <? } ?> Link to comment https://forums.phpfreaks.com/topic/160827-data-output-help/ Share on other sites More sharing options...
keeps21 Posted June 3, 2009 Share Posted June 3, 2009 Try this - it probably isn't the best way to do it, but it should work. <?php $image_path = 'flyers/'; // Retrieve data from database $sql = "SELECT * FROM flyers WHERE uid = " . $_SESSION['id']; $result = mysql_query($sql); // Initialise count $i = 0; // Start looping rows in mysql database. while($rows = mysql_fetch_array($result)){ ?> <div class="flyerbox" style="float:left;"> <a href="viewimage.php?maxsize=640&source=<?=$image_path.$rows['flyer'] ?>" rel="facebox"> <img src="viewimage.php?maxsize=75&source=<?=$image_path.$rows['flyer'] ?>" /></a> </div> <?php if ($i <= 9) { # if count is 9 or less increment count by 1 and loop $i++; } else {# if count is 10 add 'break' and reset counter $i = 0; ?> <div style="clear:both;"></div> <?php } } Link to comment https://forums.phpfreaks.com/topic/160827-data-output-help/#findComment-848840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.