[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Filtering data with Checkboxes

Posted on 2009-02-17
12
Medium Priority
?
293 Views
Last Modified: 2013-12-12
Experts, I am interested in filtering the results of my dataset based on the user's selections.

I'd like to have check boxes that can be checked or unchecked and will allow my users to add or remove criteria to the search.

I found a site that functions exactly how I want mine to work:
http://www.ajmadison.com/b.php/Side-by-Side;Refrigerators/N~26

From the looks of the URL, it looks like the condition string is added to the URL.  

I'm interested in doing something like this but I can't find any information about how to do this.  I think it's php, but can't tell what else is needed.  Is there AJAX involved?

Has anyone done something like this and would you have any examples of how to do this?

Thanks in advance,

-dsg
0
Comment
Question by:dsg138
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 2

Expert Comment

by:Unspoken1
ID: 23666456
Ajax definatley,
Non ajax approach >>
Just send the checked to a php script via a form and have it search mysql via what has been checked.
0
 
LVL 15

Expert Comment

by:quincydude
ID: 23666490
I believe the example page is not using ajax. Just like Unspoken1 mentioned, put all the checkboxs in a form, and trigger a form submit if any checkbox is being checked/unchecked using onclick event. The form should be sending to the query function so it made the suitable query and return the result back to the page.
0
 
LVL 19

Expert Comment

by:Michael701
ID: 23666725
First, it's not ajax, second it's not a checkbox.

They are actually images
http://www.ajmadison.com/phpdocs/ajtest/images/endeca/miltsel_unchecked.gif
with a href locations that are links to process the button pressed
http://www.ajmadison.com/b.php/KitchenAid;Refrigerators/N~26+4294967287
 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dsg138
ID: 23674261
Thanks for the feedback.

I've done HREF Locations before, but in this case, it looks like each of the criteria are either added to the string or removed from the string (if it's already added).

So you can have 5 different criteria all on one HREF location.

I'm not sure how to do that part.  

Does anyone have any examples on how to do that?
0
 
LVL 19

Expert Comment

by:Michael701
ID: 23674448
sure you can have a bunch of criteria, they did some off coding and made it look like part of the url. but in general it's done something like this

selection.php?brand=KitchenAid&Price=500,1000&Color=Black,Stainless
0
 

Author Comment

by:dsg138
ID: 23674926
Thanks...

So in your example above:
selection.php?brand=KitchenAid&Price=500,1000&Color=Black,Stainless

Let's say I no longer want Price=500,1000 in my Criteria.
I would click the checkbox icon next to $500 - $1000.

How would I make the HREF dynamically remove that criteria at the same time keeping all the other criteria?
0
 
LVL 19

Expert Comment

by:Michael701
ID: 23675246
No that link would just NOT have any price variable

selection.php?brand=KitchenAid&Color=Black,Stainless
0
 
LVL 15

Assisted Solution

by:quincydude
quincydude earned 200 total points
ID: 23676727
Please check the behavior of the example site you have given. Then clicking one box, the page is renewed right away. So you can guess that each time when the page loads, the value of the href of the checkboxes is different. The most be generated when the html code is generated according to the options user selected. Each box do not only provide the link of that checkbox's option but also the existing page's options.

Say, when first time the page loads the link of the AGA box is only
selection.php?brand=AGA

but if the user clicked GE and when the page loads again, that link of AGA would become
selection.php?brand=AGA,GE

So when user click AGA this time, both criteria will be submitted.
0
 
LVL 2

Expert Comment

by:Unspoken1
ID: 23677278
I never noticed the whole page reload, I thought it was ajax, but you can go about it with a non ajax approach. I think the author wants us to write code for him.
0
 

Author Comment

by:dsg138
ID: 23681513
QuincyDude,

I did notice that the checkbox'a link changes after each refresh.  And the links change based on the multiple criteria selected.

So really, it would have to remember the Criteria in some kind of String, perhaps $Criteria.

I would first have to check if that value was already added.
If it was, then the link would remove the new criteria, if not, it would add it.
Then each link would be something like $Criteria + (or -) $NewCriteria?

Then the new criteria would be passed to the link at every page refresh?

I want to make sure I understand the basic concept... is that it?
0
 
LVL 19

Accepted Solution

by:
Michael701 earned 800 total points
ID: 23683739
yes, in general here's an outline of the code


// untested code, you'll have to also fill in a few missing parts, like the sql_query and actual database select
 
$sql_command="select brand from products order by brands";
 
while ($product=mysql_fetch_assoc($rs_products))
{
  $brand=explode($_GET['brand']));
  if (in_array($product['brand']))
  {
  // checked
  $brand=','.$_GET['brand']; // comma is needed if first element
  str_replace (','.$product['brand'], '', $brand); // should strip out this brand from list
  $url=... '&brand='. urlencode(substr($brand,1)); // strip off extra comma
  }
  else
  {
  // not checked
  if ($_GET['brand'] =='')
    $brand=$product['brand'];
  else
    $brand=$GET['brand'].','.$product['brand'];
  $url=... '&brand='. urlencode($brand);
  }

Open in new window

0
 

Author Closing Comment

by:dsg138
ID: 31548996
This makes since.  I think I understand the concept.  Thanks for clarifying it for me.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 dynamically set the form action using jQuery.
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 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