joe_ma Posted June 28, 2014 Posted June 28, 2014 On a site for a band I want to list all the gigs of the band, divided in three sections, coming up, today, past gigs. To produce the list I have the following code: <?php $timestamp = time(); $t = date("d.m.Y", $timestamp); $heute = $pages->find("parent=/konzertliste/, Datum=$t"); $gigs = $pages->find("parent=/konzertliste/, Datum>$t, sort=Datum"); $gigspast = $pages->find("parent=/konzertliste/, Datum<$t, sort=-Datum"); if (count($heute)) { echo "<h2>Heute</h2>"; //todays gigs, if any echo "<div class='block-group gig_list'>"; echo "<p class='block gig_date'>{$heute->Datum}, {$heute->Zeit} Uhr</p>"; //echo date("j. F Y", $page->modified); echo "<p class='block gig_ort'><a href='{$heute->url}'>{$heute->Ort}</a></p></div>"; } if (count($gigs)) { echo "<h2>Demnächst</h2>"; //gigs coming up } $out = ''; foreach($gigs as $gig){ $out .= "<div class='block-group gig_list'>"; $out .="<p class='block gig_date'>{$gig->Datum}, {$gig->Zeit} Uhr</p>"; //echo date("j. F Y", $page->modified); $out .="<p class='block gig_ort'><a href='{$gig->url}'>{$gig->Ort}</a></p></div>"; } echo $out; if (count($gigspast)) { echo "<h2>Bisher</h2>"; //past gigs } $out = ''; foreach($gigspast as $gigpast){ $out .= "<div class='block-group gig_list'>"; $out .="<p class='block gig_date'>{$gigpast->Datum}, {$gigpast->Zeit} Uhr</p>"; //echo date("j. F Y", $page->modified); $out .="<p class='block gig_ort'><a href='{$gigpast->url}'>{$gigpast->Ort}</a></p></div>"; } echo $out; ?> While it works as wanted for the gigs coming up and past, it doesn't for todays gig. On the frontend I get only the following output: Heute , Uhr And when I change the ">" in the fourth line to ">=" it works also correctly and todays gig is also listed in the "Demnächst" part. So why does it not in the todays part? Thanks for help
marcus Posted June 28, 2014 Posted June 28, 2014 (edited) Looks like you're looping through $gigs and $gigspast, but are trying to output $heute directly. Though it's unusual to have several gigs on one day (I guess, don't know the band ) $heute will return a page collection. Try either foreach($heute as $gigheute) { ... } and better rename them vars, or outputting $heute->first()->Datum. edit: Fixed typo Edited June 28, 2014 by marcus 1
Wanze Posted June 28, 2014 Posted June 28, 2014 You forgot to foreach loop over the gigs of today. $heute is a PageArray, not a Page. Cheers Edit: Marcus won the race 1
diogo Posted June 28, 2014 Posted June 28, 2014 Also, you are looking for the events that will happen in this precise millisecond try using Datum=today instead of Datum=$t 1
joe_ma Posted June 28, 2014 Author Posted June 28, 2014 Thank you all for these answers – most valuable ones, as always. You forgot to foreach loop over the gigs of today. $heute is a PageArray, not a Page. That solved the problem. trey using Datum=today instead of Datum=$t Thanks also for this one.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now