[英]Results Database of Zend Framework
I am doing a database query in this way: 我正在以这种方式进行数据库查询:
foreach ( $_SESSION['cart'] as $product )
{
$id = (int)$product['id'];
$select = $this->table->select();
$select->where("id=$id");
$this->view->products = $this->table->fetchAll($select);
}
And in the view, I did it this way: 并认为,我是这样做的:
<?php foreach($this->products as $product) : ?>
<tr>
<td><img src="<?php echo $product->image;?>" width="190px"/><td>
<td><?php echo $product->name;?><td>
<td><?php echo $product->weight/1000 ?><td>
<td><?php //echo $this->currency($product->price);?><td>
<td>x<td>
<td><input type="text" value="<?php echo $_SESSION['cart'][$product->id]['qtd'] ?>" /><td>
<td><input type="submit" name="remove" value="Remover" /><?php echo $product->id; ?><td>
</tr>
<?php endforeach; ?>
But the results are null. 但是结果为空。 Can anyone help me? 谁能帮我?
--UPDATE-- -更新-
I tried to do this: 我试图这样做:
$this->view->products = array();
foreach ( $_SESSION['cart'] as $product )
{
$id = (int)$product['id'];
$select = $this->table->select();
$select->where("id=$id");
$this->view->products[$id] = $this->table->fetchAll($select);
}
But the results remain null. 但是结果仍然为空。 I managed to do the old way, but I only returns the last result, because the array is overwritten. 我设法用旧的方法,但是我只返回了最后一个结果,因为数组被覆盖了。
您缺少'from'部分,因此查询不知道要从哪个表中选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.