简体   繁体   中英

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'部分,因此查询不知道要从哪个表中选择。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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