project3 Posted March 4, 2008 Share Posted March 4, 2008 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 More sharing options...
sasa Posted March 4, 2008 Share Posted March 4, 2008 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 https://forums.phpfreaks.com/topic/94188-array-in-drop-down-box/#findComment-482558 Share on other sites More sharing options...
project3 Posted March 4, 2008 Author Share Posted March 4, 2008 thanks. I had figured it out just like you had put. I just couldn't find the topic solved link anymore. Thanks very much though! Link to comment https://forums.phpfreaks.com/topic/94188-array-in-drop-down-box/#findComment-482610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.