Jump to content

Greater than today


davo
 Share

Recommended Posts

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

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

"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()) {
  • Like 3
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...