davo Posted October 11, 2013 Share Posted October 11, 2013 I'm using this to extract a number of listing from the database: $garagesales = $pages->find("town_select=$town,sort=-Date"); then I list them off like this: echo "<tr bgcolor=' $rowcolour '><td> $catlogo </td><td><a href='{$c->url}'>{$c->address1}</a></td><td><a href='{$c->url}'>{$c->address2}</a></td><td>{$c->postcode}</td><td>{$c->Date}</td></tr>"; The first task I want to achieve is to add a selector at the top on one of the pages to only select where the date is greater than today; I'm a little unsure how to do this. Is there a special variable to do something like this? $garagesales = $pages->find("town_select=$town, Date>today, sort=-Date"); Link to comment Share on other sites More sharing options...
maba Posted October 11, 2013 Share Posted October 11, 2013 Hi davo, sure, it exists! Have you tried today? See here.. Link to comment Share on other sites More sharing options...
davo Posted October 11, 2013 Author Share Posted October 11, 2013 Well that makes sense, so any idea why my example doesn't filter the results? Link to comment Share on other sites More sharing options...
Wanze Posted October 11, 2013 Share Posted October 11, 2013 davo, If "Date" is the name of a date field, it should work. What exactly does not work? The sorting? Link to comment Share on other sites More sharing options...
davo Posted October 11, 2013 Author Share Posted October 11, 2013 I acutely tried this; If ($c->Date>today) { $future="p"; }else{ $future=""; } Echo $future; But they always turn out p... Like this: http://www.garagesalefinder.co.uk/listing-parent/bournemouth I'm pretty novice at php, let alone process wire. Link to comment Share on other sites More sharing options...
davo Posted October 11, 2013 Author Share Posted October 11, 2013 So, I got the filter working but my second task I wanted to mark future and past listings; I can see the variable result changing, but it doesn't seem to be for the right listings: echo "<table ><tr><th>Type</th><th>Sale Name</th> <th>Address</th><th>Post Code</th><th>Date</th></tr>"; $garagesales = $pages->find("town_select=$town,sort=-Date"); foreach($garagesales as $c){ $cat="$c->sale_category"; if($cat==1108){ $catlogo = "<img src='{$config->urls->templates}/images/garage_sale_icon_mini.png' alt='Garage Sale' width='20' >"; } elseif ($cat==1109){ $catlogo = "<img src='{$config->urls->templates}/images/car-icon.png' alt='Carboot Sale' width='20' >";} elseif ($cat==1122){ $catlogo = "<img src='{$config->urls->templates}/images/experience-icon.png' alt='Special Sale' width='20' height='20' >";} elseif ($cat==1124){ $catlogo = "<img src='{$config->urls->templates}/images/antique-telephone.png' alt='Vintage' width='20' >";} else {$catlogo="";} $colourcount = 0; if ($countercolour % 2 !=0) #odd row $rowcolour = "#99CCFF"; else #even row $rowcolour = "#F0F0F0 "; $future = ""; //reset it $Dated = $c->Date; //put the pw variable as a standard php variable // echo $Dated; $today = date('d/m/Y h:i a', time()); // make up the variable for today // echo $today; if ($Dated>$today){ $future = "f";}else{$future="p";} //compare the Dated variable to todays date and if its greater mark it with an f else p for past echo "<tr bgcolor=' $rowcolour '><td> $catlogo </td><td> $future <a href='{$c->url}'>{$c->address1}</a></td><td><a href='{$c->url}'>{$c->address2}</a></td><td>{$c->postcode}</td><td>{$c->Date}</td></tr>"; $countercolour++; #increase the count } echo "</table><br>"; Link to comment Share on other sites More sharing options...
maba Posted October 12, 2013 Share Posted October 12, 2013 I think that you have to use something like $today = time(); or format $Dated with strftime() and $c->getUnformatted('Dated') with your formatted $today var. 1 Link to comment Share on other sites More sharing options...
ryan Posted October 16, 2013 Share Posted October 16, 2013 "today" is something you could use within a ProcessWire selector, like below (so long as you are querying a datetime field): $garagesales = $pages->find("town_select=$town, Date>today, sort=-Date"); …but it's not a PHP language construct, so you couldn't do this: if($c->Date>today) { Like maba mentioned, you'd want to use the time() function instead, which returns the current unix timestamp. You'd also want to retrieve the "unformatted" version of "Date", as you may have it configured to output a date string rather than a unix timestamp. And you'd nee the unix timestamp (which is an integer) in order to properly compare it with time(): if($c->getUnformatted('Date') > time()) { 3 Link to comment Share on other sites More sharing options...
davo Posted October 17, 2013 Author Share Posted October 17, 2013 Thank you - that makes perfect sense now explained like that. I'm not a programmer by trade. I'd be interested to know why different people like processwire so much, but my quote would be... I like process wire, because it makes me feel smarter than what I am ! Link to comment Share on other sites More sharing options...
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