2011-05-18 83 views
0

的数据库,我这样做一个数据库查询:结果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; ?> 

但结果是空的。谁能帮我?

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

     } 

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

+0

在feareach循环的每次迭代中,你不会覆盖'$ this-> view-> products'吗?我的意思是,不应该'$ this-> view-> products'是一个数组? – Marcin 2011-05-19 00:53:28

+0

在这里发布您的整个模型类。可能你可能没有设置表名$ _name。并且感觉$ this-> select()主要是需要的,并且只有在看到Model时才能发表评论。 – 2011-05-19 04:00:07

回答

0

你错过了'从'部分,所以查询不知道从哪个表中选择。