jake2891 Posted March 8, 2009 Share Posted March 8, 2009 Hi guys, im having a bit of difficulty going through a while loop and adding values to an array. i need to add a specific value to a key in an array but everytime i do this i dont get the remaining values of the array only the one value back for example any help will be gratly appreciated . $sql = " SELECT p.propertyid_id AS PropertyId, p.floor_area_num, p.price_numeric AS AskingPrice, '' as PricePerSqFt FROM property p WHERE p.property_id = $property_id $q = mysql_query($sql); $test = array(); while($assoc = mysql_fetch_assoc($q)){ if($assoc['floor_area_num'] != "" && $assoc['AskingPrice'] != ""){ $test['PricePerSqFt'] =intval(0.5+$assoc['AskingPrice']/$assoc['floor_area_num']); }else{ $test[]= $assoc; } } im getting output like this Array ( [0] => Array ( [PricePerSqFt] => 706 ) ) and i want out put like this Array ( [0] => Array ( [PropertyId] => 1000375403 [AskingPrice] => 2150000 [floor_area_num] => 3047 [PricePerSqFt] => 706 ) ) Quote Link to comment Share on other sites More sharing options...
RussellReal Posted March 8, 2009 Share Posted March 8, 2009 while($assoc = mysql_fetch_assoc($q)){ $test = $assoc; if($assoc['floor_area_num'] != "" && $assoc['AskingPrice'] != ""){ $test['PricePerSqFt'] =intval(0.5+$assoc['AskingPrice']/$assoc['floor_area_num']); } } Quote Link to comment Share on other sites More sharing options...
jake2891 Posted March 8, 2009 Author Share Posted March 8, 2009 thank you that worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.