NFD Posted August 17, 2006 Share Posted August 17, 2006 Hi everyone,Youve all been of great help to me in the pst, and Im hoping one of you can help me out with something.What I want to do is have a query check a field of a table for data.If data exists, then the checkbox is made available (ticked by default, can be changed)If no data exists, then the box gets greyed out (unticked by default, obviously cant be changed)In this example I am looking at a table called "customer" and the field is called "cellphone"The tickbox will be part of a form, somethign like:[code] <td><input name="testing" class="textbox" type="checkbox" id="testing" value="1" /></td>[/code]Hopefully what I am asking for has made sense.Thankyou kindly in advance :) Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/ Share on other sites More sharing options...
appeland Posted August 17, 2006 Share Posted August 17, 2006 Hello,not sure what you are looking for , to disable a checkbox(any form field actually) add disabled to the tag[code]<input name="testing" class="textbox" type="checkbox" id="testing" value="1" disabled />[/code]Make the query just insert the disabled bit if there's no data.[code] <input name="testing" class="textbox" type="checkbox" id="testing" value="1" <? if (!$queryresult){echo "disabled"; } ?> /> [/code]Have fun !aNDI Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76375 Share on other sites More sharing options...
NFD Posted August 17, 2006 Author Share Posted August 17, 2006 Hi appeland, thankyou for your reply.Ive just realised that the field in question is already being queried, so a slightly different approach is required.Basically what I want is :if $result[0]['cellphone'] returns an empty fieldthen for the tickbox to be set as disabledDoes that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76392 Share on other sites More sharing options...
HeyRay2 Posted August 17, 2006 Share Posted August 17, 2006 [code]<input name="cellphone" class="textbox" type="checkbox" id="testing" value="1" <?php if (empty($result['cellphone']){echo "disabled"; } ?> />[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76395 Share on other sites More sharing options...
NFD Posted August 17, 2006 Author Share Posted August 17, 2006 ^^ That looks very close !Currently it gives this error though:[code]Parse error: syntax error, unexpected '{' in demo.php on line 379[/code]Code looks like this:[code]Line 379 <td><input name="cellphone" class="textbox" type="checkbox" id="cellphone" value="1" <?php if (empty($result['cellphone']){echo "disabled"; } ?> /> </td>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76397 Share on other sites More sharing options...
appeland Posted August 17, 2006 Share Posted August 17, 2006 we are getting the "FIMBLING FEELING" here (for everyone who has kids that makes sense :) )[code]<input name="testing" class="textbox" type="checkbox" id="testing" value="1" <? if (!$result[0]['cellphone']) {echo "disabled"; } ?>/>[/code]The "is empty" is represented by the "!" in front of the variable.tata,Andi Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76439 Share on other sites More sharing options...
NFD Posted August 17, 2006 Author Share Posted August 17, 2006 Indeed it does make sense :)I got it working using :[code]<td><input name="cellphone" class="textbox" type="checkbox" id="cellphone" value="1" <? if (!$cellnumber){echo "disabled"; } ?> /> </td>[/code]So thankyou to you both.Last step now, displaying a snipet of text next to the box saying "Function disabled" Is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76466 Share on other sites More sharing options...
appeland Posted August 17, 2006 Share Posted August 17, 2006 Hiho,besides the fact that i would not do that (not working should be enough),you can use the same code to do what ever else you want to display beside it :<? if (!$cellnumber){echo "this will not work , regardless what you do dudeldidum, hihi"; } ?> regards,andi Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76470 Share on other sites More sharing options...
NFD Posted August 17, 2006 Author Share Posted August 17, 2006 Hi Andi,I figured that would work (and it does)The message next to it was just a visual for that the customer does not have a cellnumber in the database(an explaination for why it cant be ticked I guess)All works, all is good.Thankyou :) Quote Link to comment https://forums.phpfreaks.com/topic/17870-query-to-determine-a-checkbox-greyed-out/#findComment-76478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.