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 ) ) Link to comment https://forums.phpfreaks.com/topic/148459-solved-array-manipulation-help/ 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']); } } Link to comment https://forums.phpfreaks.com/topic/148459-solved-array-manipulation-help/#findComment-779512 Share on other sites More sharing options...
jake2891 Posted March 8, 2009 Author Share Posted March 8, 2009 thank you that worked Link to comment https://forums.phpfreaks.com/topic/148459-solved-array-manipulation-help/#findComment-779607 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.