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
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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.