How to filter records by date using a slider-bar?

Posted on 2008-11-14
Last Modified: 2012-05-05
Hello again,

I would like to add a slider-bar to my site on which to filter markers retrieved from my database, by date (YEAR).

The following SQL query returns the distinct YEARS for which i have records - each of which i would like to be a notch on my slider:
$query_years = mysql_query("Select distinct YEAR(date) from locations order by date");

I asked the following question "How do i add increments to my slider" - which mplungian answered:

Now i need to know...

1. How do i add the distinct years from the SQL query as increments to my slider - please can you show me how this is done?

2. How do i set each increment to only return records from the corresponding year - e.g.
"SELECT * FROM locations WHERE YEAR(date) = date"

I suspect that i will need to disable my current database queries while the slider is in use. Ideally the first  (default) notch on the slider would display all records/markers.

Any help and advice greatly appreciated
Question by:Daniish
    LVL 49

    Expert Comment

    You could first have a query:

    $query = 'SELECT DISTINCT YEAR(date) FROM locations';

    $res = mysql_query($query) or trigger_error("There was an error in $query: " . mysql_error());

    $years = array();
    while($row = mysql_fetch_array($res)) {
      $years[] = $row[0];

    From the results of this you can extract the min and max and even separate increments. However, you might not want to skip any years in your slider as that might confuse users anyhow.

    echo 's.Minimum = ' . min($years).';';
    echo 's.Maximum = ' . max($years).';';

    Author Comment

    I intend on displaying a message to say which year of records is being displayed - so hopefully that will prevent users being confused.

    Can you tell me how i can extend:

    >>     echo 's.Minimum = ' . min($years).';';
    >>     echo 's.Maximum = ' . max($years).';';

    - to display each distinct year as an individual increment ?
    LVL 49

    Expert Comment


    I'm not sure what you mean by "each distinct year as an individual increment" (I'm not native english, which might be part of the problem).

    Do you mean a slider which just has has values 2005,2006,2009 when only these three years are available?

    Author Comment

    Yes you're right that's what i mean.

    For instance i would like the results of this query to form the slider values:
    $query_years = mysql_query("Select distinct YEAR(date) from locations order by date");
    LVL 49

    Accepted Solution

    As far from the slider documentation, this is not supported. I cannot find an alternative slider type inside the webfx widgets list that supports this.

    Author Comment

    Oh dear. Do you know of any alternative slider that would support this?

    Author Closing Comment

    Well in so much as you have identified its not possible i now need to close this question and award you for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Shoutout to Emily Plummer ( for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now