$username Posted July 10, 2007 Share Posted July 10, 2007 Hello All, Here is the code that I am using and I want to know if yes and no must be stored in the database to get the selected one from the database to be populated. <p> <td><font color="blue">Paid:</font></td> <td><select name="Paid"> <option selected="<? echo $formVars["Paid"]; ?>"><? echo $formVars["Paid"]; ?></option> <option value="No">No</option> <option value="Yes">Yes</option> </select><big></big></td> </tr> </p> Here is what happens now Quote Link to comment Share on other sites More sharing options...
$username Posted July 10, 2007 Author Share Posted July 10, 2007 Here is the code that I am using and I want to know if yes and no must be stored in the database to get the selected one from the database to be populated. <p> <td><font color="blue">Paid:</font></td> <td><select name="Paid"> <option selected="<? echo $formVars["Paid"]; ?>"><? echo $formVars["Paid"]; ?></option> <option value="No">No</option> <option value="Yes">Yes</option> </select><big></big></td> </tr> </p> Here is what happens now Quote Link to comment Share on other sites More sharing options...
wcsoft Posted July 10, 2007 Share Posted July 10, 2007 You could do something like this: <? $yes_sel = ""; $no_sel = ""; if ($formVars['Paid'] == "No") { $no_sel = "selected='selected'"; } else { $yes_sel = "selected='selected'"; } // end if echo <<<HTMLHERE <select name="Paid"> <option value="No" $no_sel>No</option> <option value="Yes" $yes_sel>Yes</option> </select> HTMLHERE; ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 <p> <td><font color="blue">Paid:</font></td> <td><select name="Paid"> <?php $no_opt = '<option value="No" '; $yes_opt = '<option value="Yes" '; if ($formVars["Paid"] == "No") $no_opt .= 'selected=selected'; else $yes_opt .= 'selected=selected'; $no_opt .= '>'; $yes_opt .= '>'; ?> <?php echo $no_opt;?>No</option> <?php echo $yes_opt;?>Yes</option> </select><big></big></td> </tr> </p> Sort of sloppy but will do the trick. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 10, 2007 Share Posted July 10, 2007 <?php //$result['Paid'] is the db value echo "<select name=\"Paid\">"; echo " <option value=\"No\"".(($result['Paid']=='No')?' selected="selected"':'').">No</option>"; echo " <option value=\"Yes\"".(($result['Paid']=='Yes')?' selected="selected"':'').">Yes</option>"; echo "</select>"; ?> Quote Link to comment Share on other sites More sharing options...
$username Posted July 10, 2007 Author Share Posted July 10, 2007 <?php //$result['Paid'] is the db value echo "<select name=\"Paid\">"; echo " <option value=\"No\"".(($result['Paid']=='No')?' selected="selected"':'').">No</option>"; echo " <option value=\"Yes\"".(($result['Paid']=='Yes')?' selected="selected"':'').">Yes</option>"; echo "</select>"; ?> I am using this code to update data that is in the database. What I would like is the code to pull what the database has, and then use it in the drop down box. But I do not want the drop down to have 2 yes or no in the drop down. But I still would like the drop down box to populate the yes or no that the database has listed. Thank you, Brett Quote Link to comment Share on other sites More sharing options...
$username Posted July 10, 2007 Author Share Posted July 10, 2007 I used this and it seems to work ok. <td><font color="blue">Paid:</font></td> <td><select name="Paid"> <?php $no_opt = '<option value="No" '; $yes_opt = '<option value="Yes" '; if ($formVars["Paid"] == "No") $no_opt .= 'selected=selected'; else $yes_opt .= 'selected=selected'; $no_opt .= '>'; $yes_opt .= '>'; ?> <?php echo $no_opt;?>No</option> <?php echo $yes_opt;?>Yes</option> </select><big></big></td> </tr> </p> Thanks guys. Brett Quote Link to comment 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.