brem13 Posted March 4, 2009 Share Posted March 4, 2009 ok, so i have a code on my page that displays 'featured' pictures on my site. it looks through one of my databases and only displays 'featured' pics. and im trying to have it display 4 pictures per row on my page. when i try to make a while loop and put a line break after 4 records it shows 4 of every picture. can somone help me to understand how to have it loop through and put a line break after every 4th picture. any help to understand how to do loops will be appreciated, as this is a part of programming ive always had trouble with. thank you code i have now is below. <h1>Featured Pics</h1> <?php include("../../../configpic.php"); $username1 = basename(dirname(__FILE__)) ; $username2 = strtolower($username1); $featured = "Yes"; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); $result = mysql_db_query($database, "select * from $username2 WHERE featured = '$featured'") or die (mysql_error()); $folder = "galleries/members/".$username1; while ($qry = mysql_fetch_array($result)) { $c = 1; while($c < 5) { echo '<a href="'.$qry[album].'/'.$qry[picture].'"><img src="'.$qry[album].'/thumbs/'.$qry[picture].'"></a><br />'; $c++; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147951-solved-line-break-after-every-4-records-from-mysql-database/ Share on other sites More sharing options...
brem13 Posted March 4, 2009 Author Share Posted March 4, 2009 some help please please? Quote Link to comment https://forums.phpfreaks.com/topic/147951-solved-line-break-after-every-4-records-from-mysql-database/#findComment-776544 Share on other sites More sharing options...
wildteen88 Posted March 4, 2009 Share Posted March 4, 2009 Change while ($qry = mysql_fetch_array($result)) { $c = 1; while($c < 5) { echo '<a href="'.$qry[album].'/'.$qry[picture].'"><img src="'.$qry[album].'/thumbs/'.$qry[picture].'"></a><br >; $c++; } to $i = 1; while ($qry = mysql_fetch_array($result)) { echo '<a href="'.$qry[album].'/'.$qry[picture].'"><img src="'.$qry[album].'/thumbs/'.$qry[picture].'"></a>'; if($i == 4) { echo '<br />'; $i = 0; // reset counter } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/147951-solved-line-break-after-every-4-records-from-mysql-database/#findComment-776566 Share on other sites More sharing options...
brem13 Posted March 4, 2009 Author Share Posted March 4, 2009 thank you sooo much!! Quote Link to comment https://forums.phpfreaks.com/topic/147951-solved-line-break-after-every-4-records-from-mysql-database/#findComment-776603 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.