我已经知道如何从数据库获取信息并在视图中显示它们,但我不知道如何在控制器中计算Zend Framework中的表行,我已连接到数据库并获取信息并且在视图中这个控制器,我以前用过静态值。我希望只要它们存在就显示信息。
控制器:
.
.
.
$AModel = new Model_A();
$select = $AModel->fetchAll($AModel->select()->where('user_id = ?', $part_mail ));
$this->view->rowArray = $select->toArray();
$num_rows = mysql_num_rows($select);
echo $num_rows;
.
.
.
查看:
<?php
for ($i=0 ; $i<=3; ++$i)
{
print '<tr><td>uid:'. ($this->rowArray[$i]['uid']).'</td>';
print '<td>online_status:'. ($this->rowArray[$i]['online_status']).'</td>';
print '<td>failed_logins:'. ($this->rowArray[$i]['failed_logins']).'</td></tr>';
}?>
答案 0 :(得分:0)
试试这个,
$args=array(
'host' =>'localhost',
'username' =>'root',
'password' =>'',
'dbname' =>'dbname');
$db = Zend_Db::Factory('PDO_MYSQL',$args);
$select = $db->select()
->from('table_name')
->where('user_id = ?', $part_mail )
$stmt = $db->query($select);
$result = $stmt->fetchAll();
答案 1 :(得分:0)
试试这个:
的控制器:强>
$AModel = new Model_A();
$select = $AModel->fetchAll($AModel->select()->where('user_id = ?', $part_mail ));
$rowCount = count($select);
if ($rowCount > 0) {
echo "found $rowCount rows";
$this->view->rowCount = count($select);
$this->view->rowArray = $select->toArray();
} else {
echo 'no rows matched the query';
}
查看:强>
<?php
for ($i=0 ; $i<=$this->rowCount; ++$i)
{
print '<tr><td>uid:'. ($this->rowArray[$i]['uid']).'</td>';
print '<td>online_status:'. ($this->rowArray[$i]['online_status']).'</td>';
print '<td>failed_logins:'. ($this->rowArray[$i]['failed_logins']).'</td></tr>';
}?>