簡體   English   中英

從數據庫行中回顯返回值

[英]Echo return values from rows from db

使用別名名稱時獲得結果集的值並加入使用zend framwork生成的SQL會有所不同嗎?

關於從這個問題中選擇答案產生的SQL,我想將所有結果打印在.phtml文件中。

我像這樣

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

  ?>

當我打印$this->rows的大小時,它返回正確的行數,但是不打印任何東西?

編輯這里是我打印$ 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] => ) 

如果使用的是在其他問題中接受的查詢,則字段名稱應與您期望的一樣。

我通常只是var_dump $row來查看我所期望的:

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

這應該使您對每行包含的內容非常了解,而沒有$rows所有行李。

該行不是對象,而是一個數組,可以這樣獲得:

print $row['rep_id']

呵呵,這就是為什么我將您指向ReferenceMap i Zend_Db_Tables。 檢查我對您先前問題的回答。

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

使用上一個問題中的代碼,您可以這樣做:

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

那是小菜一碟

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM