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

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
Who is Participating?
RoonaanConnect With a Mentor Commented:
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.
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).';';
DaniishAuthor Commented:
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 ?
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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?
DaniishAuthor Commented:
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");
DaniishAuthor Commented:
Oh dear. Do you know of any alternative slider that would support this?
DaniishAuthor Commented:
Well in so much as you have identified its not possible i now need to close this question and award you for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.