| Welcome to WebmasterWorld Guest from 18.104.22.168 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|checkbox value from a form to mysql query|
| 10:23 am on Apr 6, 2011 (gmt 0)|
i have (amongst other options) 3 checkboxes
the form result is sent to a php page which queries the database and all works fine
trying to incorporate the 0/1 options is becoming a nightmare
name | area | option1 | option2 | option3
joe | north | 1 | 0 | 0
bill | south | 0 | 1 | 1
fred | north | 1 | 1 | 0
the option are from the checkboxes
the main search is on area from a select option in the form but i need to pick up if any of the options are ticked
if someone wants north & option2 :
if i use radio boxs or a select then the 0 values of the options get picked up ie
but in my query how do i only select rows where option2=1
| 11:17 am on Apr 6, 2011 (gmt 0)|
SELECT * FROM `tableName` WHERE `option2` = 1;
Two things; firstly, ensure that if the option fields are only holding 1 or 0, set them up using a the enum() option to avoid any erroneous insertions..
Secondly, remember that fields that are numerical will not need to have quotes around them, if you do, this will cause all sorts of errors later on.
Hopefully that will answer your query.
| 11:26 am on Apr 6, 2011 (gmt 0)|
sorry, i shouldve clarified more - the problem is that the query is coming from a get
so i have WHERE option2=" . $_GET['option2'] . " etc
i need to be able to filter out the =0 ones that get sent in the url
or if i do it on checkboxes how do i filter out in the query -
option1=" . $_GET['option1'] . " OR option2=" . $_GET['option2'] . "
this fails on the checkbox one since only boxes that are ticked send the variable
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved