Hi I've been struggling with the most efficient way of doing this. I have an array like this
array(3) {
[0]=>
object(stdClass)#495 (4) {
["year"]=>
string(4) "2015"
["month"]=>
string(1) "1"
["dayofmonth"]=>
string(2) "29"
["posts"]=>
string(1) "3"
}
[1]=>
object(stdClass)#521 (4) {
["year"]=>
string(4) "2015"
["month"]=>
string(1) "1"
["dayofmonth"]=>
string(2) "28"
["posts"]=>
string(1) "2"
}
[2]=>
object(stdClass)#522 (4) {
["year"]=>
string(4) "2015"
["month"]=>
string(1) "1"
["dayofmonth"]=>
string(2) "25"
["posts"]=>
string(1) "1"
}
}
And I have the following values
$d = 29, $m = 1, $y = 2015
What I want to do is find which item in the array [0,1,2] is the next date before the date given by my $d, $m and $y variables.
For example, the answer below would be [1]
If the date was $d=28
then it would be [2]
If the day was $d=25
then it would return false.
The issue is the array could cover a number of years so it needs to match exactly all 3 keys and then return the key number after the found key. The array will always be in descending date order
Is this possible?
EDIT:
I am trying to query a list of items on a date basis so it will show
29 JAN 2015
Click NEXT
It will show the next day which if there is an item will just be day minus 1 but if not it will be the day minus [x]
So the list could be
29 JAN 2015
{items}
28 JAN 2015
{items}
25 JAN 2015
{items}
10 DEC 2014
{items}
29 JAN 2014
{items}
...
25 JAN 1999
{items}
and I want to be able to have this so it just shows the most up to date, then someone can click to show the next dates bunch of items.
If there's an easier way to do this via a dynamic mySQL it would be useful
FURTHER EDIT
I can extract just the date too
array(3) {
[0]=>
object(stdClass)#495 (2) {
["post_date"]=>
string(19) "2015-01-29 14:23:28"
["posts"]=>
string(1) "3"
}
[1]=>
object(stdClass)#521 (2) {
["post_date"]=>
string(19) "2015-01-28 14:24:05"
["posts"]=>
string(1) "2"
}
[2]=>
object(stdClass)#522 (2) {
["post_date"]=>
string(19) "2015-01-25 14:41:43"
["posts"]=>
string(1) "1"
}
}
With the view to select the first [20] number of posts and then "next" would load in the next days worth of posts