Jump to content

Sort Array


shage

Recommended Posts

I am sorting on date of images which are the thumbnail of the tutorial, now i call the array doing the date, which gives me a long list of tutorials,  i would like to only list 2 from each day then a break with adver then list 2 more from another date etc, whats the best way to do this, right now it just lists all the tutorials in order well the first 7 but breaks for adver etc

Link to comment
Share on other sites

well i have a folder where images are named 20071010-photoshop-text1.jpg and the next 6 might be 20071010-photoshop-text(2-6).jpg

 

i want it to search the folder

 

image 1

image 2

adver

image 3

image 4

adver

image 5

image 6

 

see what im saying, right now i can post all them on the page but i have no breaks in the loop to apply adver

Link to comment
Share on other sites

well i have a folder where images are named 20071010-photoshop-text1.jpg and the next 6 might be 20071010-photoshop-text(2-6).jpg

 

i want it to search the folder

 

image 1

image 2

adver

image 3

image 4

adver

image 5

image 6

 

see what im saying, right now i can post all them on the page but i have no breaks in the loop to apply adver

 

Well, at last you have given us clue about the images, but there seems to be contradiction in this example and your earlier statement about only 2 from each day then an advert then 2 from the next day etc.

 

And where do the adverts come from? How are they stored?

Link to comment
Share on other sites

they are all in a folder in that folder list several other folders in which have the name of the tutorial, inside the folder in the thumb which has the date, right now i have it sort into date, it grabs them all i limited to 7 so it only pulls 7, just trying to think of a way to break after two for a advertisement

Link to comment
Share on other sites

you only need to count to 2

<?php
$images  = array ('a', 'b', 'c', 'd', 'e', 'f', 'g');  // your array of images.

$k = 0;           // counter

foreach ($images as $im)
{
    echo "<img src='$im'><br>";
    if (++$k == 2)
    {
        echo "advert here<br>";
        $k = 0;
    }
}
?>

Link to comment
Share on other sites

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.