Professional Web Applications Themes

Populating drop down menu - PHP Development

I use the following code snippet to build a drop down menu with the results of a query. How can I set the initial value of this input based on the result of another query? What I am trying to do is update records in the data base. The field WkEndDate is pulled along with the rest of the record and the drop down menu is built from a table of valid WkEndDate values. echo ("Weekend Date: <select name='WkEndDate'/> "); while ($row = mysql_fetch_array($result2)) { echo ("<option value='" . $row["Date"] . "'>" . date('F j, Y', strtotime($row["Date"]))); } echo ("</select><br>"); ...

  1. #1

    Default Populating drop down menu

    I use the following code snippet to build a drop down menu with the
    results of a query. How can I set the initial value of this input based
    on the result of another query?

    What I am trying to do is update records in the data base. The field
    WkEndDate is pulled along with the rest of the record and the drop down
    menu is built from a table of valid WkEndDate values.

    echo ("Weekend Date: <select name='WkEndDate'/> ");

    while ($row = mysql_fetch_array($result2)) {

    echo ("<option value='" . $row["Date"] . "'>" .

    date('F j, Y', strtotime($row["Date"])));

    }

    echo ("</select><br>");

    The initial value in the form is always the first value from result2 and
    I would like it to be the value from result1 (not shown).

    Thanks,

    Mike
    Mike Guest

  2. #2

    Default Re: Populating drop down menu

    Mike Wilcox wrote: 
    // extraneous "/" _____________________________^___ ?

    (snip) 

    The echo inside the while should compare result2 to result1 and set the
    appropriate "selected". Something like:


    while($row = mysql_fetch_array($result2)) {
    echo "<option value='", $row["Date"], "'";

    # I'm guessing $result1 was fetched into $row1
    if ($row1['Date'] == $row['Date']) echo " selected";

    echo ">", date('F j, Y', strtotime($row["Date"])), '</option>';
    }
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--
    Pedro Guest

  3. #3

    Default Re: Populating drop down menu

    Pedro Graca <com> wrote in
    news:c1d7ul$1hle73$news.uni-berlin.de:
     
    > // extraneous "/" _____________________________^___ ?
    >
    > (snip) 
    >
    > The echo inside the while should compare result2 to result1 and set
    > the appropriate "selected". Something like:
    >
    >
    > while($row = mysql_fetch_array($result2)) {
    > echo "<option value='", $row["Date"], "'";
    >
    > # I'm guessing $result1 was fetched into $row1
    > if ($row1['Date'] == $row['Date']) echo " selected";
    >
    > echo ">", date('F j, Y', strtotime($row["Date"])), '</option>';
    > }[/ref]

    Sorry to show such a newbie streak.

    So 'selected' makes the particular option selected as 'checked' does in a
    radio button?

    Thanks,

    Mike
    Mike Guest

  4. #4

    Default Re: Populating drop down menu

    Mike Wilcox wrote: 
    >
    > Sorry to show such a newbie streak.
    >
    > So 'selected' makes the particular option selected as 'checked' does in a
    > radio button?[/ref]

    Right. Read all about it at
    http://www.w3.org/TR/html4/interact/forms.html#h-17.6
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--
    Pedro Guest

  5. #5

    Default Re: Populating drop down menu

    Pedro Graca <com> wrote in
    news:c1e6k4$1hi5v6$news.uni-berlin.de:
     
    >>
    >> Sorry to show such a newbie streak.
    >>
    >> So 'selected' makes the particular option selected as 'checked' does
    >> in a radio button?[/ref]
    >
    > Right. Read all about it at
    > http://www.w3.org/TR/html4/interact/forms.html#h-17.6[/ref]

    Pedro,

    Thanks a lot. That code worked after a tried several times and finally
    got it copied in correctly. :)

    Mike
    Mike Guest

Similar Threads

  1. Populating Drop-down menu with unused numbers
    By rickaclark54 in forum Coldfusion - Getting Started
    Replies: 13
    Last Post: June 26th, 02:00 AM
  2. Populating Drop Down Boxes from a database
    By gskar in forum Coldfusion Database Access
    Replies: 4
    Last Post: March 14th, 10:49 PM
  3. Populating DHTML menu from MySQL
    By Jason in forum PHP Development
    Replies: 2
    Last Post: January 23rd, 04:29 PM
  4. How do I build Drop Down menu using Menu magic with Database result
    By Shaiju V Raman webforumsuser@macromedia.com in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: November 20th, 02:51 PM
  5. Replies: 2
    Last Post: September 11th, 07:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139