Jump to content

[SOLVED] Single Line IF ELSE..?


A JM

Recommended Posts

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>

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

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

 

  Quote

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>"

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,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.