You can take the selected items posted to your page and use in_array() to
search for the current item as your code creates the list.  this is a chunk
of code that i use to do the same thing.  I wrote this a long time ago, so
there may be better ways to do this....but it works. ;-)

<<snip>>
if (in_array($value, $array)) {
     print "<option value=\"$value\" selected>".$value."</option>\n";
} else {
     print "<option value=\"$value\">".$value."</option>\n";
}
<<snip>>
hth,
jeff


                                                                                       
                             
                    "Aaron Wolski"                                                     
                             
                    <aaronjw@marte       To:     <[EMAIL PROTECTED]>                
                             
                    kbiz.com>            cc:                                           
                             
                                         Subject:     [PHP-DB] Help with select box - 
multiple...                   
                    02/05/2003                                                         
                             
                    08:42 AM                                                           
                             
                                                                                       
                             
                                                                                       
                             




Hi All,

Sorry to be a pain on this one as it is sorta off topic.. but any help
would be awesome.

I'm creating a report for Product Popularity in which the Admin is
present with a form and they have the ability to select A product or
multiple products from a drop down combo box.

The form is submitted to itself.. and all works.. meaning I can select
multiple products from the drop down box and the results displayed fine.
However, I want to SHOW to the user (in the drop down box) which
products were selected. Things work fine if I am selecting on product -
meaning it show the product name being sleected.. however, if multiple
products are selected it doesn't show any as being selected.

The select box code is below as is the script to iterate through the
products array.

Thanks all.


*** product select box ***

<select name="products[]" class="selectcontent" size="3" multiple>


<option value="" class="selectcontent">Product</option>

<?php


$productQuery = db_query("SELECT name, SUM(quantity) as mostSold FROM
CartTable WHERE submitted=1 GROUP BY name ORDER BY mostSold DESC");

while ($productResult = db_fetch($productQuery)) {

?>





<option value="<?php echo $productResult['name']; ?>" <?php if
($productResult['name'] == $str_products) echo "selected"; ?>
class="selectcontent"><?php echo $productResult['name']; ?></option>

<?php

              }

?>


</select>



*** array iteration code **

if ($products) {

              if (is_array($products)) {

                           $str_products = implode(",",$products);

              }

              else {

                           $str_products = $products;

              }

              echo $str_products;

}




Aaron





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to