简体   繁体   English

从数据库行中回显返回值

[英]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. 使用别名名称时获得结果集的值并加入使用zend framwork生成的SQL会有所不同吗?

Regarding to the sql resulted from the selected answer in this question I want to print all result in .phtml file. 关于从这个问题中选择答案产生的SQL,我想将所有结果打印在.phtml文件中。

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?! 当我打印$this->rows的大小时,它返回正确的行数,但是不打印任何东西?

Edit here's what I get when I print $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] => ) 

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: 我通常只是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')
  ?>

This should give you a pretty good idea of what each row contains with out all the baggage that $rows has. 这应该使您对每行包含的内容非常了解,而没有$rows所有行李。

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

print $row['rep_id']

Heh, and that's why I pointed You to ReferenceMap i Zend_Db_Tables. 呵呵,这就是为什么我将您指向ReferenceMap i Zend_Db_Tables。 Check my answer to Your previous question. 检查我对您先前问题的回答。

https://stackoverflow.com/a/9905206/1278879 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 那是小菜一碟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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