• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

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:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_23286465.html

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
0
Daniish
Asked:
Daniish
  • 4
  • 3
1 Solution
 
RoonaanCommented:
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).';';
0
 
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 ?
0
 
RoonaanCommented:
Hi,

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?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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");
0
 
RoonaanCommented:
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.
0
 
DaniishAuthor Commented:
Oh dear. Do you know of any alternative slider that would support this?
0
 
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now