简体   繁体   中英

Echo return values from rows from db

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] => ) 

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.

该行不是对象,而是一个数组,可以这样获得:

print $row['rep_id']

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM