Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:19:50+00:00 2026-05-26T11:19:50+00:00

I created classes Rankings and DateFilter . Each rankings class has a DateFilter class

  • 0

I created classes Rankings and DateFilter.

Each rankings class has a DateFilter class that should produce the cutoff date. I am trying to be able to create a filter so that everything created after that date will be displayed in a table.

However, the comparison does not work. Can you see a problem?

Here is my DateFilter class:

<?php

include ("Filter.php");

class DateFilter extends Filter
{
    //@param daysOld: how many days can be passed to be included in filter
    //Ex. If daysOld = 7, everything that is less than a week old is included
    private $interval;

    public function DateFilter($daysOld)
    {
        $this->interval = new DateInterval('P'.$daysOld.'D');
    }

    //@Return: Returns a DateTime that is the earliest possible date to be included in the filter
    function createLimitDate()
    {
        $now = new DateTime();
        return $now->sub($this->interval);
    }

    //generates SQL code for checking date
    //Ex. WHERE limitDate > created... if > means before
    function genSQL()
    {
        $limitDate = $this->createLimitDate();

        return $limitDate->format('Y-m-d') . " < 'created'";
    }
}
?>

And my Rankings Class:

<?php

class Rankings 
{
    private $filter;

    //@params: $filty is the filter given to these rankings
    public function Rankings($filty)
    {
        $this->filter = $filty;
    }

    //@return: returns the html code for the rankings
    public function display()
    {
        echo '<table border="1" align="center">'.
                    '<tr align="center" style="font-weight:bold;">
                        <b><td>#</td><td>NAME</td><td>Date</td></b>
                    </tr>
                    ';

            //hardcoding DB
            $where = $this->filter->genSQL();

            $qry = mysql_query("SELECT * FROM  `pix` 
                                WHERE $where
                                ");
                if (!$qry)
                    die("FAIL: " . mysql_error());

            $i = 1;
            while($row = mysql_fetch_array($qry))
            {
                $name = $row['uniquename'];
                $created = $row['created'];
                echo ' <tr>
                            <td>'. $i . '</td>'.
                            '<td>' . $name . '</td>'.
                            '<td>'. $created . '</td>'.
                        '</tr>';

                $i += 1;
            }

            echo '</table>';
            echo $where;
    }
}
?>

I’m calling it like this:

$test = new DateFilter(100);

$rankings = new Rankings($test);
$rankings->display();

In that example, nothing is displayed, even though I’m sure everything in my datebase was uploaded less than 100 days ago.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:19:51+00:00Added an answer on May 26, 2026 at 11:19 am

    Throw in some quotes around the date you’re passing to MySQL, and drop the quotes around your column name:

    return "'" . $limitDate->format('Y-m-d') . "' < created";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like Linq but find that once the designer has created my classes I
I am trying to write T4 template to create wrapper classes for classes created
I created two classes. In each class there are UIButton and the related event.
We have a set of classes created that depend on Prototype's Class implementation (and
Say I've got a domain model created from C# classes like this: public class
I have several classes, that all derives from SuperClass. When the classes are created,
Is it possible to add dict functionality to user created classes? ie: class Foo(object):
i have created two classes Standard and Family which extend abstract class Room ,
I have created some classes in a module, f.i. Request (app/models/api/request.rb) class Api::Request end
Why are abstract or interface classes created, or when should we use abstract or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.