Dropdown list - Trying to get default populated from db.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oli

    #1

    Dropdown list - Trying to get default populated from db.

    Nooby question but when I try and get this to work (it should identify which
    rows in the database have GK, MID, DEF, FWD against them and then put
    SELECTED into the option value to give a default of what the entry is
    currently) it just adds SELECTED to all the results as if $row["Position"]
    is returning true against all four conditions? What am I doing wrong?

    Thanks,

    O.

    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    echo("<td>" . $row["Surname"] . "</td>");
    echo("<td>" . $row["TeamName"] . "</td>");
    ?>
    <td><select name="select2">
    <option value="GK"<? if ($row["Position"] = "GK") {?>SELECTED<?}
    ?>>GK</option>
    <option value="DEF"<? if ($row["Position"] = "DEF") {?>SELECTED<?}
    ?>>DEF</option>
    <option value="MID"<? if ($row["Position"] = "MID") {?>SELECTED<?}
    ?>>MID</option>
    <option value="FWD"<? if ($row["Position"] = "FWD") {?>SELECTED<?}
    ?>>FWD</option>
    ?>>
    </select></td>
    <?

    echo("<td>" . $row["Selected"] . "</td>");
    }


  • Pieter Nobes

    #2
    Re: Dropdown list - Trying to get default populated from db.

    Oli wrote:[color=blue]
    > <td><select name="select2">
    > <option value="GK"<? if ($row["Position"] = "GK") {?>SELECTED<?}
    > ?>>GK</option>
    > <option value="DEF"<? if ($row["Position"] = "DEF") {?>SELECTED<?}
    > ?>>DEF</option>
    > <option value="MID"<? if ($row["Position"] = "MID") {?>SELECTED<?}
    > ?>>MID</option>
    > <option value="FWD"<? if ($row["Position"] = "FWD") {?>SELECTED<?}
    > ?>>FWD</option>
    > ?>>
    > </select></td>
    > <?
    >
    > echo("<td>" . $row["Selected"] . "</td>");
    > }[/color]

    You have to use == instead of =. = means assignment, so you actually
    assign GD, DEF, ... to $row['Position'], which returns true since it
    worked. If you'd use if ( $row['Position'] == '...' ) your script should
    work.

    --
    Pieter Nobels

    Comment

    • Oli

      #3
      Re: Dropdown list - Trying to get default populated from db.

      You beauty!! :D

      O.

      "Pieter Nobes" <pieterRE@MOVE. opengate.be> wrote in message
      news:1LOWc.2245 98$7v3.11034718 @phobos.telenet-ops.be...[color=blue]
      >
      > You have to use == instead of =. = means assignment, so you actually
      > assign GD, DEF, ... to $row['Position'], which returns true since it
      > worked. If you'd use if ( $row['Position'] == '...' ) your script should
      > work.
      >
      > --
      > Pieter Nobels[/color]


      Comment

      • Oli

        #4
        Re: Dropdown list - Trying to get default populated from db.

        Next question I guess is how do I get this huge table to pass its variables
        back to the database after a submit is um..submitted..

        From what I have read, normally I would use the POST method and that would
        pass the variables and then I could put them back in the database but as all
        of these variables have the same names, how best to do it?

        O.

        "Oli" <ovbigfootcom@m ail.com> wrote in message
        news:cggj8j$mda $1@titan.btinte rnet.com...[color=blue]
        > You beauty!! :D
        >
        > O.
        >[/color]


        Comment

        • Tim Van Wassenhove

          #5
          Re: Dropdown list - Trying to get default populated from db.

          In article <cggjlv$qhs$1@h ercules.btinter net.com>, Oli wrote:[color=blue]
          > Next question I guess is how do I get this huge table to pass its variables
          > back to the database after a submit is um..submitted..
          >
          > From what I have read, normally I would use the POST method and that would
          > pass the variables and then I could put them back in the database but as all
          > of these variables have the same names, how best to do it?[/color]


          <?php
          if (isset($_POST['submit']))
          {
          echo "SELECTED VALUES: ";
          while (list ($key, $val) = each ($_POST['multiselect']))
          {
          echo "$val ";
          }
          echo "<br>\n";
          }
          ?>

          <form method="post">
          <select name="multisele ct[]" multiple>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          </select>
          <input type="submit" value="submit" name="submit" />
          </form>



          --
          Tim Van Wassenhove <http://home.mysth.be/~timvw>

          Comment

          • Tony Marston

            #6
            Re: Dropdown list - Trying to get default populated from db.


            "Oli" <ovbigfootcom@m ail.com> wrote in message
            news:cggjlv$qhs $1@hercules.bti nternet.com...[color=blue]
            > Next question I guess is how do I get this huge table to pass its
            > variables
            > back to the database after a submit is um..submitted..
            >
            > From what I have read, normally I would use the POST method and that would
            > pass the variables and then I could put them back in the database but as
            > all
            > of these variables have the same names, how best to do it?[/color]

            If you construct your HTML document using data from multiple database rows
            then you will have duplicate field names. The way around this is to index
            each fieldname by row number, as in field[$row].

            When the form is posted back PHP will present you the data in the format:

            fieldname: array =
            0: string = value
            1: string = value
            2: string = value

            You simply step through this like any other array. Easy when you know how.

            HTH.

            --
            Tony Marston

            This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




            Comment

            Working...