aeris130 Posted May 21, 2006 Share Posted May 21, 2006 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.[code]$table=$_GET['table'];$query = "SELECT * FROM $table WHERE $kolumn LIKE \"%$trimmed%\" AND approved='yes' ORDER BY name ASC";[/code]The value table is currently set by[code]<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>[/code]But rather then just selecting one table, I'd like to use checkboxes instead.[code]<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>[/code]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? Link to comment https://forums.phpfreaks.com/topic/10108-checkbox-search/ Share on other sites More sharing options...
.josh Posted May 21, 2006 Share Posted May 21, 2006 name="table[]"in each tag. this will create an array of each value selected. Link to comment https://forums.phpfreaks.com/topic/10108-checkbox-search/#findComment-37624 Share on other sites More sharing options...
aeris130 Posted May 21, 2006 Author Share Posted May 21, 2006 [code]<input type="checkbox" name="table[]" value="tcg_dex_ex_legend_maker">Ex Legend Maker[/code]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). Link to comment https://forums.phpfreaks.com/topic/10108-checkbox-search/#findComment-37631 Share on other sites More sharing options...
.josh Posted May 21, 2006 Share Posted May 21, 2006 $table = $_GET['table'];if you have 3 checkboxes selected then $table is your array of those three values. echo $table[0]; // echos the first valueecho $table[1]; // echos the 2nd valueecho $table[2]; // echos the 3rd valueso 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 Link to comment https://forums.phpfreaks.com/topic/10108-checkbox-search/#findComment-37633 Share on other sites More sharing options...
aeris130 Posted May 21, 2006 Author Share Posted May 21, 2006 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? Link to comment https://forums.phpfreaks.com/topic/10108-checkbox-search/#findComment-37642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.