A JM Posted June 20, 2009 Share Posted June 20, 2009 I need some help with a single line IF ELSE statement - hopefully someone can help... I was under the impression this would work but I'm not having any luck. <?php $answ=$row_rstocdetail['pol_mortgage']=="y" ? "YES" : "NO"; ?> Thanks. A JM, Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/ Share on other sites More sharing options...
MadTechie Posted June 20, 2009 Share Posted June 20, 2009 <?php $answ = ($row_rstocdetail['pol_mortgage']=="y")?"YES":"NO"; ?> EDIT: question.. What are you trying to do ? Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/#findComment-859951 Share on other sites More sharing options...
SetToLoki Posted June 20, 2009 Share Posted June 20, 2009 hehe just asked about same thing you might find this topic usefull Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/#findComment-859952 Share on other sites More sharing options...
A JM Posted June 20, 2009 Author Share Posted June 20, 2009 I'm trying to set the value of a YES/NO Option from a recordset so that the end user can edit the field if needed. Just reaching out for some solution... this didn't work. <select size="1" name="pol_mortgage" tabindex="32" class="form-inputitem"></option> <option value="<?php echo htmlentities($row_rstocdetail['mortgage'], ENT_COMPAT, 'utf-8'); ?>"><?php echo htmlentities($row_rstocdetail['mortgage'], ENT_COMPAT, 'utf-8'); ?></option> <option value="Y">YES</option> <option value="N">NO</option></select> Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/#findComment-859953 Share on other sites More sharing options...
MadTechie Posted June 20, 2009 Share Posted June 20, 2009 is the field 'pol_mortgage' or 'mortgage' ? heres two options <select size="1" name="pol_mortgage" tabindex="32" class="form-inputitem"></option> <?php if(strtolower($row_rstocdetail['pol_mortgage'])=="y") { echo "<option value=\"Y\" selected=\"selected\">YES</option>"; echo "<option value=\"N\">NO</option>"; }else{ echo "<option value=\"Y\">YES</option>"; echo "<option value=\"N\" selected=\"selected\">NO</option>"; } ?> </select> OR <select size="1" name="pol_mortgage" tabindex="32" class="form-inputitem"></option> <select size="1" name="pol_mortgage" tabindex="32" class="form-inputitem"></option> <?php $sel = (strtolower($row_rstocdetail['pol_mortgage'])=="y") ?> <option value="Y" <?php echo ($sel)?"selected=\"selected\"":"";?>>YES</option>"; <option value="N" <?php echo (!$sel)?"selected=\"selected\"":"";?>>NO</option>"; </select> ?> Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/#findComment-859957 Share on other sites More sharing options...
A JM Posted June 20, 2009 Author Share Posted June 20, 2009 It also has an empty/null option.. is that feasible to add into that? So there really no need for a single line - I see. Can you also perform a CASE statement similarly? Thanks. A JM, Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/#findComment-859961 Share on other sites More sharing options...
MadTechie Posted June 20, 2009 Share Posted June 20, 2009 It also has an empty/null option.. is that feasible to add into that? Just add a blank one at the top <option value=""></option>"; is neither are selected then its the default So there really no need for a single line - I see. Can you also perform a CASE statement similarly? You could do this in a case statement but its only 2 options this or that! so if seams better of course you could do this <option value="" <?php echo ($row_rstocdetail['pol_mortgage']="")?"selected=\"selected\"":"";?>></option>" <option value="Y" <?php echo ($row_rstocdetail['pol_mortgage']="Y")?"selected=\"selected\"":"";?>>YES</option>"; <option value="N" <?php echo ($row_rstocdetail['pol_mortgage']="N")?"selected=\"selected\"":"";?>>NO</option>" <option value="M" <?php echo ($row_rstocdetail['pol_mortgage']="M")?"selected=\"selected\"":"";?>>MayBe</option>" Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/#findComment-859981 Share on other sites More sharing options...
A JM Posted June 21, 2009 Author Share Posted June 21, 2009 Since the Option has a blank option the field in the DB can be ISNULL which when using the following gives me "NO" as opposed to a blank? <option value="" <?php echo ($row_rstocdetail['pol_mortgage']="")?"selected=\"selected\"":"";?>></option>" <option value="Y" <?php echo ($row_rstocdetail['pol_mortgage']="Y")?"selected=\"selected\"":"";?>>YES</option>"; <option value="N" <?php echo ($row_rstocdetail['pol_mortgage']="N")?"selected=\"selected\"":"";?>>NO</option>" <option value="M" <?php echo ($row_rstocdetail['pol_mortgage']="M")?"selected=\"selected\"":"";?>>MayBe</option>" Can I actually test for ISNULL and set the option to be blank? Thanks. A JM, Quote Link to comment https://forums.phpfreaks.com/topic/162977-solved-single-line-if-else/#findComment-860852 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.