Zend框架结果数据库

发布于 2024-11-07 18:25:10 字数 1562 浏览 3 评论 0原文

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

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乜一 2024-11-14 18:25:10

您缺少“来自”部分,因此查询不知道要从哪个表中选择。

You're missing the 'from' part, so the query doesn't know which table to select from.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文