mike12255 Posted March 31, 2009 Share Posted March 31, 2009 I have had a problem now for a while i tried playing around with the code and failed, i posted code on her and failed, so now im trying to ask how you would go about doing this and mabey i can get ideas. Im sql'ing my database to get image locations and then i want to post X amount of pictures on a line and have it go down a line everytime the number X is reached. Is that clear enough - if not ask questions Link to comment https://forums.phpfreaks.com/topic/151992-solved-how-would-you-do-this/ Share on other sites More sharing options...
.josh Posted March 31, 2009 Share Posted March 31, 2009 $cols = 5; // number of columns here $count = 1; while(some condition here that loops through results) { if ($count % $cols == 0) { echo "<br />"; // or close a tr and open a new one, etc.. $count++; } //whatever code here Link to comment https://forums.phpfreaks.com/topic/151992-solved-how-would-you-do-this/#findComment-798201 Share on other sites More sharing options...
mike12255 Posted March 31, 2009 Author Share Posted March 31, 2009 whats this line do?? $count % $cols == 0) never seen % used before Link to comment https://forums.phpfreaks.com/topic/151992-solved-how-would-you-do-this/#findComment-798204 Share on other sites More sharing options...
.josh Posted March 31, 2009 Share Posted March 31, 2009 it's a modulus operator. It divides one thing by another and returns the remainder. The idea is if you divide the counter by the columns and it returns a zero remainder, you've reached a column count divisible by 5, or in other words, the 5th column in the current row, so start a new row. Link to comment https://forums.phpfreaks.com/topic/151992-solved-how-would-you-do-this/#findComment-798208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.