Hi there,

Take a look at the following snippet below. It is similar to what you're
looking for without having to bugger about duplicating loads of lines for
each store. Just add a new one to the array if required.

Best Regards,
- Paul -

<select name=MonthSelected size=1>
<?php

  $MonthArr = array (
                     "January",
                     "February",
                     "March",
                     "April",
                     "May",
                     "June",
                     "July",
                     "August",
                     "September",
                     "October",
                     "November",
                     "December",
                    );

  reset($MonthArr);

  foreach ($MonthArr as $MonthName) {
    echo "<option VALUE=\"$MonthName\"";
    if ($MonthName == $MonthSelected) echo " selected";
    echo ">";
    echo "$MonthName";
  }

?>
</select>


----- Original Message -----
From: "Steve Cayford" <[EMAIL PROTECTED]>
To: "Jeff Grossman" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, September 05, 2001 11:36 PM
Subject: Re: [PHP-DB] Forms Question


>
> On Wednesday, September 5, 2001, at 04:50  PM, Jeff Grossman wrote:
>
> > Hello,
> > Here is the code I have:
> >
> > while ($row=mysql_fetch_array($result)) {
> >    $store=$row["store"];
> >    $jobdesc=$row["jobdesc"];
> > echo "<FORM METHOD=post ACTION=update.php>";
> > echo "<P>Store:
> >       <Select NAME=\"$store\">
> >          <option VALUE=\"Signal Hill\">Signal Hill
> >          <option VALUE=\"Reseda\">Reseda
> >          <option VALUE=\"Orange\">Orange
> >          <option VALUE=\"West Covina\">West Covina
> >          <option VALUE=\"Riverside\">Riverside
> >          <option VALUE=\"Norwalk\">Norwalk
> >          <option VALUE=\"Fountain Valley\">Fountain Valley
> >          <option VALUE=\"Pasadena\">Pasadena
> >          <option VALUE=\"Redondo Beach\">Redondo Beach
> >          <option VALUE=\"San Bernardino\">San Bernardino
> >          <option VALUE=\"Kearny Mesa\">Kearny Mesa
> >          <option VALUE=\"San Marcos\">San Marcos
> >          <option VALUE=\"Chino\">Chino
> >          <option VALUE=\"Coporate Office\">Corporate Office
> >       </select></P>";
> > echo "<P><INPUT TYPE=text SIZE=35 NAME=\"Jobdesc\"
> > VALUE=\"$jobdesc\"></P>";
> > echo "<p><INPUT TYPE=submit VALUE=\"submit\" LABEL=\"Save
> > Changes\"></P>";
> > }
> >
> >
> > Is want I am trying to do possible?  I want the value which is stored in
> > $store to automatically fill in on the drop down list.  But, for some
> > reason it is defaulting to the first option, and not using the value
> > that is in the database.
> >
> > Can I use a drop down menu, or should I just go to radio buttons?
> >
> > Thanks,
> > Jeff
>
> If I understand your question...
>
> In order to have your value preset in the drop down list you need
> indicate that with
> <option value=\"blahblah\" selected>blahblah
>
> What I've been using for this is a hash like this:
>
> while ($row=mysql_fetch_array($result)) {
>     $selected = array();
>     $selected[$row["store"]] = "selected";
>     $store=$row["store"];
>     $jobdesc=$row["jobdesc"];
>     echo "<FORM METHOD=post ACTION=update.php>";
>     echo "<P>Store:";
>     echo "<Select NAME=NameOfVariableToBePosted>"
>     echo "      <option VALUE=\"Signal Hill\" " . $selected["Signal
> Hill"] . ">Signal Hill";
>     echo "      <option VALUE=\"Reseda\" " . $selected["Reseda"] .
> ">Reseda";
> ...etc, etc., etc.
>
> something along those lines, anyway. So, if $row["store"] == "Signal
> Hill", then $selected["Signal Hill"] will be set to "selected", while
> $selected["Reseda"] and all the others will be blank.
>
> This is a very keen thing about php.
>
> -Steve
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to