Jump to content


Photo

Checkbox-search


  • Please log in to reply
4 replies to this topic

#1 aeris130

aeris130
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 21 May 2006 - 07:46 AM

I'm trying to configure a search-function on my site, so that users can select one or several tables to search from, using checkboxes.

$table=$_GET['table'];

$query = "SELECT * FROM $table WHERE $kolumn LIKE \"%$trimmed%\" AND approved='yes'
  ORDER BY name ASC";

The value table is currently set by

<select name="table">
  <option value ="tcg_dex_ex_legend_maker">Ex Legend Maker</option>
  <option value ="tcg_dex_ex_delta_species">Ex Delta Species</option>
  <option value ="tcg_dex_ex_unseen_forces">Ex Unseen Forces</option>
  </select>

But rather then just selecting one table, I'd like to use checkboxes instead.

<input type="checkbox" name="table" value="tcg_dex_ex_legend_maker">Ex Legend Maker<br>
<input type="checkbox" name="table" value="tcg_dex_ex_delta_species">Ex Delta Species<br>
<input type="checkbox" name="table" value="tcg_dex_ex_unseen_forces">Ex Unseen Forces<br>

Needless to say, using checkboxes like this, will only result in one of the options being used. How should I configure my query to recieve several values into $table?



#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 08:49 AM

name="table[]"

in each tag. this will create an array of each value selected.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 aeris130

aeris130
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 21 May 2006 - 09:13 AM

<input type="checkbox" name="table[]" value="tcg_dex_ex_legend_maker">Ex Legend Maker

Like that? For some reason, it won't display any results at all. Are there any other changes in the code that I need to do?

for example, $table=$_GET['table'];

still recieves its value from "table", not "table[]", right? (or rather, "table%5B%5D" as it is generated in the url).

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 09:26 AM

$table = $_GET['table'];

if you have 3 checkboxes selected then $table is your array of those three values.

echo $table[0]; // echos the first value
echo $table[1]; // echos the 2nd value
echo $table[2]; // echos the 3rd value

so in your sql query if you did

select * from $table[0] where blah=blah

or whatever, it would get the results from the first table that you checked. Obviously you can use a loop to loop through each one, or use a join
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 aeris130

aeris130
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 21 May 2006 - 10:06 AM

I think I've gotten the array to work now, even though it selects the last option i check instead of the first (and it still won't select more then one table).

Anyway, I'm not that versed in looping queries or using join's. Are there any (newbie-friendly) documentation written about this?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users