结果Zend框架数据库

时间:2011-05-18 18:54:57

标签: php zend-framework zend-db zend-db-table

我正在以这种方式进行数据库查询:

        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; ?>

但结果为空。任何人都可以帮助我吗?

- UPDATE -

我试着这样做:

$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);

        }

但结果仍为空。我设法做旧的方式,但我只返回最后的结果,因为数组被覆盖。

1 个答案:

答案 0 :(得分:0)

您缺少'from'部分,因此查询不知道要从哪个表中进行选择。