raryre23 Posted July 12, 2008 Share Posted July 12, 2008 Firstly I'm not even sure if it should be a for loop or whether it should be a while one, or what the difference even is. But anyway it seems to be working fine apart from one thing. It's meant to display up to seven images one after each other but the problem is that if there is any less than seven images in the database then it just displays all of the images it has and then error messages. How can I get it so that it does not display any error messages? <?php $sql="select * from images where (username= '$username') ORDER BY picurl"; $res=mysql_query($sql); for($i=0; $i < 7; $i++) { $picurl= mysql_result($res,$i,"picurl"); ?> <img src="<?php print $picurl ?>" /> <?php } ?> Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/114449-solved-help-with-for-loop/ Share on other sites More sharing options...
Barand Posted July 12, 2008 Share Posted July 12, 2008 one way <?php $sql="select * from images where (username= '$username') ORDER BY picurl"; $res=mysql_query($sql); $limit = min (7, mysql_num_rows($res)); for($i=0; $i < $limit; $i++) { $picurl= mysql_result($res,$i,"picurl"); echo "<img src='$picurl' />"; } ?> Link to comment https://forums.phpfreaks.com/topic/114449-solved-help-with-for-loop/#findComment-588513 Share on other sites More sharing options...
raryre23 Posted July 12, 2008 Author Share Posted July 12, 2008 one way <?php $sql="select * from images where (username= '$username') ORDER BY picurl"; $res=mysql_query($sql); $limit = min (7, mysql_num_rows($res)); for($i=0; $i < $limit; $i++) { $picurl= mysql_result($res,$i,"picurl"); echo "<img src='$picurl' />"; } ?> It's working great - thank you Link to comment https://forums.phpfreaks.com/topic/114449-solved-help-with-for-loop/#findComment-588525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.