lovephp Posted March 20, 2016 Share Posted March 20, 2016 how do i do this someone? here is my code what is want is if there is just just one image then it display as the code below <?php $stm = $db->prepare("SELECT * FROM images WHERE id = '".$id."'"); $stm->execute(); $rs = $stm->fetchAll(); foreach( $rs as $img ) { ?> <div style="display: inline-block;"> <img src="uploads/images/<?php echo $img['img']; ?>" class="fancybox"/> </div> <?php } ?> if more than 1 record than only the first image will be in <div style="display: inline-block;"><img src="uploads/images/<?php echo $img['img']; ?>" class="fancybox"/></div> and rest will be inside just <div><img src="uploads/images/<?php echo $img['img']; ?>" class="fancybox"/> </div> <div><img src="uploads/images/<?php echo $img['img']; ?>" class="fancybox"/> </div> <div><img src="uploads/images/<?php echo $img['img']; ?>" class="fancybox"/> </div> <div><img src="uploads/images/<?php echo $img['img']; ?>" class="fancybox"/> </div> without the style="display: inline-block;" from 2nd record onwards Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted March 20, 2016 Solution Share Posted March 20, 2016 counter = 1 for each image { if counter = 1 { output div code with inline-block } else { output plain div code } output image code output closing div counter++ } 1 Quote Link to comment Share on other sites More sharing options...
lovephp Posted March 20, 2016 Author Share Posted March 20, 2016 not getting it bro Quote Link to comment Share on other sites More sharing options...
lovephp Posted March 20, 2016 Author Share Posted March 20, 2016 counter = 1 for each image { if counter = 1 { output div code with inline-block } else { output plain div code } output image code output closing div counter++ } still not getting it how to get it into my codes Quote Link to comment Share on other sites More sharing options...
lovephp Posted March 20, 2016 Author Share Posted March 20, 2016 did it thanks a ton Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted March 20, 2016 Share Posted March 20, 2016 We have CSS for this: :first-child 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.