At 3:37 PM -0800 3/8/01, Nicole Lallande wrote:
>$len = mysql_num_rows($result);
>for ($i=0; $i<=$len; $i++) {
>   echo "<option value=\"$catid[$i]\">$catid</option>";
>}

I believe your problem is in that code becuase it's ambiguous and 
because $catid is an array and you're treating it as a regular 
variable.

what you should do is something like:

        while ($row = mysql_fetch_array($result)) {
          $rowid[] = $row["dnaProd_ID"];
          $catid[] = $row["Cat_ID"];
          $desc[] = $row["Description"];
          $size[] = $row["Pkg_size"];
          $price[] = $row["Price"];
        }

for($i = 0; $i < sizeof($catid); $i++)
{
        $cat = $catid[$i];
        echo "<option value=\"$cat\">$cat</option>";
}

or you could build this up during your first loop:

        $optionValues = "";
        while ($row = mysql_fetch_array($result)) {

        $cat = $row["Cat_ID"];

        $optionValues .= "<option value=\"$cat\">$cat</option>\n";
        }

then just echo $optionValues whenever you want.

OR

you can create a generic function you can use anytime you want to 
make an option list, just pass in an array of options:

GenerateOptionValues($optionArr)
{
        $string = "";
        foreach($optionArr as $option}
        {
                $string .= "<option value=\"$option\">$option</option>\n";
        }

return $string;
}

or if you need different values from the options, pass in an 
associateive array:

GenerateOptionValues($optionArr)
{
        $string = "";
        foreach($optionArr as $option => $value}
        {
                $string .= "<option value=\"$value\">$option</option>\n";
        }

        return $string;
}

alright, sorry for going on and on.

-aaron

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