Jump to content

Archived

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

FloridaNutz

Quick and Easy Questions

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]

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Add a semi-colon ( ; ) at the end of this line:
[code=php:0]$opts = array("ucf","north","downtown","disney","citiwalk")[/code]

So its:
[code=php:0]$opts = array("ucf","north","downtown","disney","citiwalk");[/code]


You should be fine now.

Share this post


Link to post
Share on other sites

×

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.