homepage Welcome to WebmasterWorld Guest from 50.19.206.49
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
checkbox value from a form to mysql query
adeibiza




msg:4293022
 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

the table:

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 :

search.php?area=north&option2=1

if i use radio boxs or a select then the 0 values of the options get picked up ie

search.php?area=north&option1=0&option2=1&option3=0

but in my query how do i only select rows where option2=1

 

Matthew1980




msg:4293051
 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.

Cheers,
MRb

adeibiza




msg:4293061
 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved