shage Posted October 12, 2007 Share Posted October 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/ Share on other sites More sharing options...
darkfreaks Posted October 12, 2007 Share Posted October 12, 2007 so your doing something like <?php $array= array($tutorials,$date); $array= asort($date); /// sort tutorials by date ?> Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-367949 Share on other sites More sharing options...
darkfreaks Posted October 12, 2007 Share Posted October 12, 2007 <?php $tutorials="select *from tutorials values(tutorial,date) LIMIT 2"; ///limiting the tutorials by 2 only $array= array($tutorials,$date); $array= asort($date); /// sort tutorials by date ?> Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-367970 Share on other sites More sharing options...
shage Posted October 12, 2007 Author Share Posted October 12, 2007 now if i limit by two and then limit again by 2 will it be the same 2? Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368046 Share on other sites More sharing options...
darkfreaks Posted October 12, 2007 Share Posted October 12, 2007 im not sure why would you need to limit it twice? Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368053 Share on other sites More sharing options...
shage Posted October 12, 2007 Author Share Posted October 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368064 Share on other sites More sharing options...
darkfreaks Posted October 12, 2007 Share Posted October 12, 2007 well searching is a different thing what i said above will sort the array by the date and the Limit will limit it to 2 entries Period. Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368066 Share on other sites More sharing options...
shage Posted October 12, 2007 Author Share Posted October 12, 2007 yea i see that just trying to figure out how to sort the next 2 out in another table table-2 images adver table-2 other images adver table-maybe 4 other images im frustrated lol Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368071 Share on other sites More sharing options...
Barand Posted October 12, 2007 Share Posted October 12, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368085 Share on other sites More sharing options...
shage Posted October 12, 2007 Author Share Posted October 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368087 Share on other sites More sharing options...
Barand Posted October 12, 2007 Share Posted October 12, 2007 just trying to think of a way to break after two for a advertisement Simple. Count them. You mentioned an array. What does that look like? What code do you have so far? Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368100 Share on other sites More sharing options...
shage Posted October 12, 2007 Author Share Posted October 12, 2007 how would you count them and echo 1 and 2 then adver then 3 and 4 Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368126 Share on other sites More sharing options...
Barand Posted October 12, 2007 Share Posted October 12, 2007 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368217 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.