Jump to content


Photo

Quick and Easy Questions


  • Please log in to reply
4 replies to this topic

#1 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 22 August 2006 - 04:17 AM

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?

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

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

<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


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 22 August 2006 - 06:53 AM

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

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 22 August 2006 - 01:27 PM

some reason that's not working...


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


unexpected T_FOREACH


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 August 2006 - 03:03 PM

Add a semi-colon ( ; ) at the end of this line:
$opts = array("ucf","north","downtown","disney","citiwalk")

So its:
$opts = array("ucf","north","downtown","disney","citiwalk");


You should be fine now.

#5 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 22 August 2006 - 03:07 PM

thanks, i was just about to reply that.... hense... i'm stupid lol




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users