I have an array which has the id's and my code is as following,
//Random Offer of the day
$offers = Offer::model()->findAll();
$randomOffer = null;
$dataOffer = new GreenPointsActionDataObj();
if ($offers) {
$randomNo = mt_rand(0, count($offers) - 1);
$randomOffer = $offers[$randomNo];
$dataOffer->id = intval($randomOffer->id);
$dataOffer->title = $randomOffer->name;
$dataOffer->thumbUrl = $randomOffer->thumbUrl;
$dataOffer->description = $randomOffer->description;
}
$data[] = $dataOffer;
I need this to be day based, for example it should be always one for the day and next day another random but should be same the whole day.
how can i get this done ?
This is my suggestion, when an id is taken, i should maintain it with a day stored in DB.
Try this code:
Method 1:
To get the unique offer for year.
$weekday = date('l', time()); // will return the weekday number
$randomOffer = $offers[$weekday];
Method 2
To get the unique offer for year.
$daycnt = date('z', time())+1;
$randomOffer = $offers[$daycnt];
Method 3
To get the unique offer for month.
$cur_date = date('d', time());
$randomOffer = $offers[$cur_date ];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments