<?php

class SearchController extends Zend_Controller_Action {

	public function init() {		
		$this->view->menuSel = -100;
	}	
	
	
	public function indexAction() {			
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();

		$this->view->search = $v['search'];
		
		$search = explode(" ",$v['search']);
		
		$ask = "SELECT * FROM product p";
		
		$i = 0;
		foreach( $search as $key => $val ){
			$i++;
			
			if( $i == 1 ){
				$ask = $ask." WHERE p.product_name LIKE '%".$val."%'";
			}else{
				$ask = $ask." AND p.product_name LIKE '%".$val."%'";			
			}		
		}
	//	echo$ask;
		$data = $db->query($ask)->fetchAll();
		$this->view->dataTable = $data;
	}

}
