Jump to content

Quick and Easy Questions


FloridaNutz

Recommended Posts

I have a mySQL database and an admin where I want to make a php file to edit entries in form mode...

How do I load a default php variable to a list/menu and check boxes when i can do it with text fields?

[code]<input name="barName" type="text" value="<? echo $barName ?>" size=40 maxlength=50 />[/code]

[code] <select name="barArea" selected="<? echo $barArea ?>" size="1">
    <option value=""> -- Select One --</option>
    <option value="ucf">UCF </option>
    <option value="north">North </option>
    <option value="downtown">Downtown </option>
    <option value="disney">Disney </option>
    <option value="citiwalk">Citywalk </option>
              </select>[/code]

[code]<input name="barKey[]" type="checkbox" id="barKey" value="bar" />
              Bar
              <input name="barKey[]" type="checkbox" id="barKey" value="club" />
              Club
              <input name="barKey[]" type="checkbox" id="barKey" value="food" />
              Food
              <input name="barKey[]" type="checkbox" value="dj" />
              DJ[/code]
Link to comment
Share on other sites

You need to match each option value against the current value, so it's easiest to do it in a loop

[code]<select name="barArea"  size="1">
<option value=""> -- Select One --</option>
  <?php
    $opts = array("ucf","north","downtown","disney","citiwalk")
    foreach ($opts as $val) {
        $chk = $val==$bararea ? 'selected' : '';
        echo "<option value='$val' $chk> $val</option>\n";
    }
  ?>
</select>[/code]
Link to comment
Share on other sites

some reason that's not working...

[code]

<select name="barArea" size="1">
<?php
    $opts = array("ucf","north","downtown","disney","citiwalk")
    foreach ($opts as $val) {
        $chk = $val==$bararea ? 'selected' : '';
        echo "<option value='$val' $chk> $val</option>\n"; } ?>
</select>

[/code]

unexpected T_FOREACH
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.