Jump to content

Recommended Posts

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

$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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.