0

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.

  • Won't you overwrite `$this->view->products` with each iteration of the feareach loop? I mean, shouldn't `$this->view->products` be an array? – Marcin May 19 '11 at 00:53
  • Post your whole Model class here. Probably you may not have set table name $_name . And also feel $this->select() is mostly needed, and can only comment once I see the Model . – Hari K T May 19 '11 at 04:00

1 Answers1

0

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

Lotus Notes
  • 6,302
  • 7
  • 32
  • 47