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

Filtering data with Checkboxes

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
dsg138
Asked:
dsg138
  • 4
  • 4
  • 2
  • +1
2 Solutions
 
Unspoken1Commented:
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
 
quincydudeCommented:
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
 
Michael701Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
dsg138Author Commented:
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
 
Michael701Commented:
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
 
dsg138Author Commented:
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
 
Michael701Commented:
No that link would just NOT have any price variable

selection.php?brand=KitchenAid&Color=Black,Stainless
0
 
quincydudeCommented:
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
 
Unspoken1Commented:
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
 
dsg138Author Commented:
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
 
Michael701Commented:
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
 
dsg138Author Commented:
This makes since.  I think I understand the concept.  Thanks for clarifying it for me.
0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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