title: php yii get column result from query
body: <p>I have doen a query which has retruned a result. I do not know how to retrieve the values. I only require one column value</p>
  
  <pre><code>            //print_r($_POST['Components']);
              $criteria = new CDbCriteria;
              $criteria-&gt;condition = "(original_asset_number = '". $_POST['Components']['original_asset_number'] ."')";
              $fixedAsset=FixedAsset::model()-&gt;findAll($criteria);
              print_r($fixedAsset);
              //$fixed_asset_id = $fixedAsset-&gt;fixed_asset_id;
  </code></pre>
  
  <p>How would I just get the id from the record, as it only would ever return 1 record</p>
  
  <p>@GBD</p>
  
  <p>I have tried</p>
  
  <pre><code>public function actionCreate()
      {
          $model = new Components;
          $model_fixedAsset = new FixedAsset;
          $model_comAsset = new ComAsset;
  
          // Uncomment the following line if AJAX validation is needed
          // $this-&gt;performAjaxValidation($model);
  
          if(isset($_POST['Components']))
          {
              $model-&gt;attributes=$_POST['Components'];
  
  
              // Check if asset exist and get PK
              if( $_POST['Components']['original_asset_number'] != "" ){
                  //print_r($_POST['Components']);
                  $criteria = new CDbCriteria;
                  $criteria-&gt;condition = "(original_asset_number = :original_asset_number)";
                  $criteria-&gt;params = array(":original_asset_number" =&gt;  $_POST['Components']['original_asset_number'] );
                  $fixedAsset = FixedAsset::model()-&gt;findAll($criteria);
                  //print_r($model_fixedAsset);
                  $id = $fixedAsset-&gt;fixed_asset_id;
                  print_r("model:". $id);
              }
  
  
  
              /*if($model-&gt;save())
                  $this-&gt;redirect(array('view','id'=&gt;$model-&gt;component_id));*/
          }
  
          $this-&gt;render('create',array(
              'model'=&gt;$model,
              'model_fixedAsset'=&gt;$model_fixedAsset,
              'model_comAsset'=&gt;$model_comAsset,
          ));
      }
  </code></pre>
  
  <p>but I get error</p>
  
  <pre><code>2012/09/19 13:49:26 [error] [php] Trying to get property of non-object (/opt/dam/protected/controllers/ComponentsController.php:85)
  Stack trace:
  #0 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(134): ComponentsController-&gt;runAction()
  #1 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(292): CFilterChain-&gt;run()
  #2 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(266): ComponentsController-&gt;runActionWithFilters()
  #3 /opt/dam/yii-1.1.12.b600af/framework/web/CWebApplication.php(283): ComponentsController-&gt;run()
  #4 /opt/dam/yii-1.1.12.b600af/framework/web/CWebApplication.php(142): CWebApplication-&gt;runController()
  #5 /opt/dam/yii-1.1.12.b600af/framework/base/CApplication.php(162): CWebApplication-&gt;processRequest()
  #6 /opt/dam/index.php(13): CWebApplication-&gt;run()
  REQUEST_URI=/dam/index.php?r=components/create
  in /opt/dam/protected/controllers/ComponentsController.php (85)
  in /opt/dam/index.php (13)
  </code></pre>
  
  <p>what i am trying to do is retrieve the id of a record by using a unique field within that record which is <code>original_asset_number</code>, id is called <code>fixed_asset_id</code></p>
  
  <p>print_r(model_fixed_asset);</p>
  
  <pre><code>Array ( [0] =&gt; FixedAsset Object ( [_md:private] =&gt; CActiveRecordMetaData Object ( [tableSchema] =&gt; CMysqlTableSchema Object ( [schemaName] =&gt; [name] =&gt; fixed_asset [rawName] =&gt; `fixed_asset` [primaryKey] =&gt; fixed_asset_id [sequenceName] =&gt; [foreignKeys] =&gt; Array ( ) [columns] =&gt; Array ( [fixed_asset_id] =&gt; CMysqlColumnSchema Object ( [name] =&gt; fixed_asset_id [rawName] =&gt; `fixed_asset_id` [allowNull] =&gt; [dbType] =&gt; varchar(20) [type] =&gt; string [defaultValue] =&gt; [size] =&gt; 20 [precision] =&gt; 20 [scale] =&gt; [isPrimaryKey] =&gt; 1 [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [description] =&gt; CMysqlColumnSchema Object ( [name] =&gt; description [rawName] =&gt; `description` [allowNull] =&gt; 1 [dbType] =&gt; varchar(30) [type] =&gt; string [defaultValue] =&gt; [size] =&gt; 30 [precision] =&gt; 30 [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [original_asset_number] =&gt; CMysqlColumnSchema Object ( [name] =&gt; original_asset_number [rawName] =&gt; `original_asset_number` [allowNull] =&gt; 1 [dbType] =&gt; varchar(30) [type] =&gt; string [defaultValue] =&gt; [size] =&gt; 30 [precision] =&gt; 30 [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [flag] =&gt; CMysqlColumnSchema Object ( [name] =&gt; flag [rawName] =&gt; `flag` [allowNull] =&gt; 1 [dbType] =&gt; tinyint(1) [type] =&gt; integer [defaultValue] =&gt; 0 [size] =&gt; 1 [precision] =&gt; 1 [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [disposal_date] =&gt; CMysqlColumnSchema Object ( [name] =&gt; disposal_date [rawName] =&gt; `disposal_date` [allowNull] =&gt; 1 [dbType] =&gt; date [type] =&gt; string [defaultValue] =&gt; [size] =&gt; [precision] =&gt; [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) ) [_e:private] =&gt; [_m:private] =&gt; ) [columns] =&gt; Array ( [fixed_asset_id] =&gt; CMysqlColumnSchema Object ( [name] =&gt; fixed_asset_id [rawName] =&gt; `fixed_asset_id` [allowNull] =&gt; [dbType] =&gt; varchar(20) [type] =&gt; string [defaultValue] =&gt; [size] =&gt; 20 [precision] =&gt; 20 [scale] =&gt; [isPrimaryKey] =&gt; 1 [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [description] =&gt; CMysqlColumnSchema Object ( [name] =&gt; description [rawName] =&gt; `description` [allowNull] =&gt; 1 [dbType] =&gt; varchar(30) [type] =&gt; string [defaultValue] =&gt; [size] =&gt; 30 [precision] =&gt; 30 [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [original_asset_number] =&gt; CMysqlColumnSchema Object ( [name] =&gt; original_asset_number [rawName] =&gt; `original_asset_number` [allowNull] =&gt; 1 [dbType] =&gt; varchar(30) [type] =&gt; string [defaultValue] =&gt; [size] =&gt; 30 [precision] =&gt; 30 [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [flag] =&gt; CMysqlColumnSchema Object ( [name] =&gt; flag [rawName] =&gt; `flag` [allowNull] =&gt; 1 [dbType] =&gt; tinyint(1) [type] =&gt; integer [defaultValue] =&gt; 0 [size] =&gt; 1 [precision] =&gt; 1 [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) [disposal_date] =&gt; CMysqlColumnSchema Object ( [name] =&gt; disposal_date [rawName] =&gt; `disposal_date` [allowNull] =&gt; 1 [dbType] =&gt; date [type] =&gt; string [defaultValue] =&gt; [size] =&gt; [precision] =&gt; [scale] =&gt; [isPrimaryKey] =&gt; [isForeignKey] =&gt; [autoIncrement] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) ) [relations] =&gt; Array ( [components] =&gt; CManyManyRelation Object ( [_junctionTableName:private] =&gt; [_junctionForeignKeys:private] =&gt; [limit] =&gt; -1 [offset] =&gt; -1 [index] =&gt; [through] =&gt; [joinType] =&gt; LEFT OUTER JOIN [on] =&gt; [alias] =&gt; [with] =&gt; Array ( ) [together] =&gt; [scopes] =&gt; [name] =&gt; components [className] =&gt; Components [foreignKey] =&gt; com_asset(fixed_asset, component) [select] =&gt; * [condition] =&gt; [params] =&gt; Array ( ) [group] =&gt; [join] =&gt; [having] =&gt; [order] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) ) [attributeDefaults] =&gt; Array ( [flag] =&gt; 0 ) [_model:private] =&gt; FixedAsset Object ( [_md:private] =&gt; CActiveRecordMetaData Object *RECURSION* [_new:private] =&gt; [_attributes:private] =&gt; Array ( ) [_related:private] =&gt; Array ( ) [_c:private] =&gt; [_pk:private] =&gt; [_alias:private] =&gt; t [_errors:private] =&gt; Array ( ) [_validators:private] =&gt; [_scenario:private] =&gt; [_e:private] =&gt; [_m:private] =&gt; ) ) [_new:private] =&gt; [_attributes:private] =&gt; Array ( [fixed_asset_id] =&gt; FA0008 [description] =&gt; Spectrum House - Exit panel [original_asset_number] =&gt; B0795 [flag] =&gt; 0 [disposal_date] =&gt; 2011-11-04 ) [_related:private] =&gt; Array ( ) [_c:private] =&gt; [_pk:private] =&gt; FA0008 [_alias:private] =&gt; t [_errors:private] =&gt; Array ( ) [_validators:private] =&gt; [_scenario:private] =&gt; update [_e:private] =&gt; [_m:private] =&gt; ) ) 
  </code></pre>