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

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.