Jump to content

array in drop down box


project3

Recommended Posts

Hello,

 

I have an array in a script that fills a drop down box. I want to change the values that are in the drop down array.

 

original that works -------

 

$array = array(

            'PriceHiLo' => $lang->xget('str_sort_price_hi_lo'),

              'PriceLoHi' => $lang->xget('str_sort_price_lo_hi')

                    );

 

-------------

 

Now what I want to do is use a loop from the db to fill the array. At most I get the exact string show up

in dropdown like Shrimp => Shrimp is what will show when I try. Am I going about this wrong. Below is the code I'm trying to get this to work with.

 

 

$query = "SELECT DISTINCT ds_products.pID, ds_products.foodcat, ds_product_categories.pID, ds_product_categories.catID FROM ds_products, ds_product_categories WHERE (ds_products.pID = ds_product_categories.pID) AND ds_product_categories.catID = '$c' GROUP BY foodcat";

 

 

 

 

  $result = mysql_query($query) or die(mysql_error());

 

  $numx=mysql_numrows($result);

 

  $thisx = 1;

 

 

  $xr = "";

 

  while($row = mysql_fetch_array($result, MYSQL_ASSOC))

 

  { 

 

      $foodcat = $row['foodcat'];

 

 

      if($numx != $thisx){

   

      $xr .= "'$foodcat' => '$foodcat',";

      }else{

 

      $xr .= "'seafood'  =>  'seafood'"; 

      }

   

   

 

    $thisx = $thisx + 1;

 

 

 

}

 

$array = array($xr);

 

 

Thanks in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/94188-array-in-drop-down-box/
Share on other sites

try

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
       $foodcat = $row['foodcat'];
       if($numx != $thisx){
       $xr[$foodcat] = $foodcat;
      }else{
       $xr['seafood'] = 'seafood'; 
      }
    $thisx = $thisx + 1;
}
$array = $xr;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.