Jump to content

[SOLVED] array manipulation help


jake2891

Recommended Posts

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

          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']);
               }
          }

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.