In case anyone else was confused, Rawhead sent me this:
//ok why this line?
$i = 0;
while($rsImage=mysql_fetch_array($rsImages, MYSQL_ASSOC)){
$sImage.="<a href=\"images/upload/".$rsImage["filename"]."_large.jpg\" target=_blank><img src=\"images/upload/".$rsImage["filename"].".jpg\"></a> ";
//what is this doing?
if($i % 3 == 0)
print '<br>';
//and why this line
$i++;
}
to which I responded:
First, I'll explain the strategy. We want to loop through the results, and every third picture, put into html a <br> character, signifying a line break.
Now, I'll go through it line by line:
initializes a variable $i. A variable named 'i' is often used to signify a loop counter, which is what we're using it for here.
Code: Select all
while($rsImage=mysql_fetch_array($rsImages, MYSQL_ASSOC)){
Here your friend's code pulls rows from the database. In english, it says: 'Until you run out of pictures, pull one out of the database'
Code: Select all
$sImage.="<a href="images/upload/".$rsImageї"filename"]."_large.jpg" target=_blank><img src="images/upload/".$rsImageї"filename"].".jpg"></a> ";
This line sets up HTML to display the image with a link to image_large.jpg. I removed the <br>, because that's what adds the line break, making things display vertically.
This line says: 'if the remainder of $i divided by 3 (remember that $i counts our loops) is equal to zero, do the code below.'
If $i % 3 (% means 'modulus' and signifies the remainder of a division) was equal to zero, this line only is executed, concatenating a <br> to the variable $sImage every 3rd time through the loop. Please note that I changed this line in this PM, it was incorrect before

sorry
Now that we've gone through our loop, we add 1 to the loop counter.
Finally, we re-initialize $sImage so that we can do it all over again without repeating images.
And that's it - nothing complicated, just basic math. Experiment with it, try to break it then make it work again, and you'll start learning. I also recommend the manual at php.net, phpcomplete.com, and anywhere else you can find a tutorial to start learning this stuff. Once you do, you'll get hooked like everyone else in here, I'm sure

.