0

Does it make difference to get the value of result set when using alias names and join in the SQL generated using zend framwork.

Regarding to the sql resulted from the selected answer in this question I want to print all result in .phtml file.

I make like this

 <?php   
   foreach($this->rows as $row){
          echo $row->visit_id . '  ' . $row->rep_id . '  '.$row->target;

  ?>

When I print the size of $this->rows it returns the correct number of rows, but it doesn't print any thing?!

Edit here's what I get when I print $rows

    Zend_Db_Statement_Pdo Object ( [_fetchMode:protected] => 2 [_stmt:protected] => PDOStatement Object ( [queryString] => SELECT `r`.`rep_id`, `r`.`visit_id`, `v`.`target`, `v`.`visit_id` FROM `visit_report_tb` AS `r` INNER JOIN `inspection_visits_tb` AS `v` ON v.visit_id=r.visit_id WHERE (r.visit_id = 1) ) [_adapter:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_numericDataTypes:protected] => Array ( [0] => 0 [1] => 1 [2] => 2 [INT] => 0 [INTEGER] => 0 [MEDIUMINT] => 0 [SMALLINT] => 0 [TINYINT] => 0 [BIGINT] => 1 [SERIAL] => 1 [DEC] => 2 [DECIMAL] => 2 [DOUBLE] => 2 [DOUBLE PRECISION] => 2 [FIXED] => 2 [FLOAT] => 2 ) [_defaultStmtClass:protected] => Zend_Db_Statement_Pdo [_config:protected] => Array ( [dbname] => inspection [username] => root [password] => 123456 [charset] => [persistent] => [options] => Array ( [caseFolding] => 0 [autoQuoteIdentifiers] => 1 [fetchMode] => 2 ) [driver_options] => Array ( ) ) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( ) [_enabled:protected] => [_filterElapsedSecs:protected] => [_filterTypes:protected] => ) [_defaultProfilerClass:protected] => Zend_Db_Profiler [_connection:protected] => PDO Object ( ) [_caseFolding:protected] => 0 [_autoQuoteIdentifiers:protected] => 1 [_allowSerialization:protected] => 1 [_autoReconnectOnUnserialize:protected] => ) [_attribute:protected] => Array ( ) [_bindColumn:protected] => Array ( ) [_bindParam:protected] => Array ( ) [_sqlSplit:protected] => Array ( [0] => SELECT `r`.`rep_id`, `r`.`visit_id`, `v`.`target`, `v`.`visit_id` FROM `visit_report_tb` AS `r` INNER JOIN `inspection_visits_tb` AS `v` ON v.visit_id=r.visit_id WHERE (r.visit_id = 1) ) [_sqlParam:protected] => Array ( [0] => SELECT `r`.`rep_id`, `r`.`visit_id`, `v`.`target`, `v`.`visit_id` FROM `visit_report_tb` AS `r` INNER JOIN `inspection_visits_tb` AS `v` ON v.visit_id=r.visit_id WHERE (r.visit_id = 1) ) [_queryId:protected] => ) 
3
  • Is $row really and object or is it an array? You could try to print it using print_r. Commented Mar 29, 2012 at 10:06
  • It returns Zend_Db_Statement_Pdo Object (.....) Commented Mar 29, 2012 at 10:08
  • 1
    try print_r( $this->rows->toArray() ); and look at the result. Commented Mar 29, 2012 at 11:59

3 Answers 3

1

If you are using the query you accepted in the other question, your field names should be as you expect.

I usually just var_dump $row to see what's there is what I expect:

<?php   
   foreach($this->rows as $row){
          //Zend_Debug::dump() provides formatted debug info, the second argument is a label 
          Zend_Debug::dump($row, 'Row')
  ?>

This should give you a pretty good idea of what each row contains with out all the baggage that $rows has.

Sign up to request clarification or add additional context in comments.

Comments

0

Heh, and that's why I pointed You to ReferenceMap i Zend_Db_Tables. Check my answer to Your previous question.

https://stackoverflow.com/a/9905206/1278879

Using my code from Your previous question You could've done it like this:

foreach ($reportRowset as $reportRow) {
   echo $reportRow->visit_id . '  ' . $reportRow->rep_id . '  '.$visitRow->target;
}

And that's piece of cake

2 Comments

I want to get the result as object not array, but I think your way is not peace of cake :S
$visitRow and $reportRow are Objects! They are Zend_Db_Table_Row. Of course You can override this by setting protected property $_rowClass in Your Zend_Db_Table classes (i. e. Visit and Report class - taking from my previous answer).
0

The row is not an object, its an array and it can be get like this:

print $row['rep_id']

8 Comments

Did you try print "$row->visit_id"; this?
Yes I did it returns nothing!
And what print_r($row) gives?;
Array ( [rep_id] => 1 [visit_id] => 1 [target] => loca1 ) Array ( [rep_id] => 2 [visit_id] => 1 [target] => loc2 )
I fix the problem, I print $row['rep_id']
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.