<?php 
foreach ($products as $index => $product) {
    ?>
    <h1><?php 
    echo link_to($product->getName(), "product/edit?id=" . $product->getId());
    ?>
</h1>
		<table border=1>
			<tr>
				<td>Warehouse</td>
				<td>Qty</td>
				<td>View</td>
			</tr>
			<?php 
    foreach (WarehouseTable::fetchAll() as $warehouse) {
        $stock = StockTable::fetch($warehouse->getId(), $product->getId());
        ?>
			<tr>
				<td><?php 
        echo $warehouse->getName();
        ?>
</td>
				<td><?php 
        echo $stock->getCurrentQty();
        ?>
</td>
				<td><?php 
        echo link_to("View", "stock/view?id=" . $stock->getId());
        ?>
</td>
 public function executeStocksearch(sfWebRequest $request)
 {
     $this->searchstring = $request->getParameter("searchstring");
     $requestparams = $request->getParameter("invoicedetail");
     $this->product_id = $requestparams["product_id"];
     $this->warehouses = WarehouseTable::fetchAll();
     $this->products = array();
     if ($this->searchstring != "") {
         $this->products = Doctrine_Query::create()->from('Product p')->orderBy('p.name')->where('p.name like "%' . $this->searchstring . '%"')->execute();
     } else {
         if ($this->product_id) {
             $this->products = Doctrine_Query::create()->from('Product p, p.Stock s, s.Warehouse w')->where('p.id =' . $this->product_id)->execute();
         }
     }
 }