Zend框架结果数据库
我正在以这种方式进行数据库查询:
foreach ( $_SESSION['cart'] as $product )
{
$id = (int)$product['id'];
$select = $this->table->select();
$select->where("id=$id");
$this->view->products = $this->table->fetchAll($select);
}
在视图中,我是这样进行的:
<?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; ?>
但结果为空。谁能帮助我吗?
--更新--
我尝试这样做:
$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);
}
但结果仍然为空。我设法采用旧方法,但我只返回最后一个结果,因为数组被覆盖。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少“来自”部分,因此查询不知道要从哪个表中选择。
You're missing the 'from' part, so the query doesn't know which table to select from.