Post by durai4052 » Sat Aug 29, 2015 11:47 am

Hi I am new to open cart. I need to create a simple search module

I have a table with following content and i need to perform search in the following table

store id adress NAME
1 1,xyzs ABC
2 2,cbvg SDDD
3 7,vksh FDSDF
4 8,dghdh SDFSD


Please suggest me how to proceed.
Last edited by durai4052 on Sun Aug 30, 2015 12:30 pm, edited 1 time in total.

Newbie

Posts

Joined
Mon Jul 27, 2015 2:32 pm

Post by MarketInSG » Sat Aug 29, 2015 6:17 pm

you will need to know how to write SQL statements. from there, link it up to the front end html codes to display the search box.

your request is pretty vague, so nothing much we can help you with here.


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by durai4052 » Sun Aug 30, 2015 12:20 pm

Thanks for your reply i just tried but need some assistance so pls if you could help its much appreciated


This is model

Code: Select all

$query = $this->db->query("SELECT * FROM " .  DB_PREFIX. 'store  WHERE name like "%'.$this->request->get['search'].'%" OR address like "%'.$this->request->get['search'].'%");


			$store_data = $query->rows;

		

		return $store_data;
	
	


here is controller

Code: Select all

					if (isset($this->request->get['search'])) {
			$search = $this->request->get['search'];
		} else {
			$search = '';
			
		}		
		if (isset($this->request->get['search'])) {}


if (isset($this->request->get['search'])   )  {
			$data['stores'] = array(
				'name'         => $search,
							);


			$this->load->model('setting/store');

			$results = $this->model_setting_store->getstore();

			foreach ($results as $result) {
				$data['stores'][] = array(
					'store_id' => $result['store_id'],
					'name'     => $result['name'],
					'address'  => $result['address'],
					

				);
			}
			

}

		$data['search'] = $search;
			


here is the view

Code: Select all

 <input type="text" name="search" value="<?php echo $search; ?>" placeholder="<?php echo $text_keyword; ?>" id="input-search" class="form-control" />
 <input type="button" value="<?php echo $button_search; ?>" id="button-search" class="btn btn-primary" />

<?php foreach ($stores as $store) { ?>
  <?php if ($store['store_id'] == $store_id) { ?>
  <a href="<?php echo $store['url']; ?>"><b><?php echo $store['name']; ?></b></a>
    <?php echo $store['address']; ?>

<br />
  
  
  <?php } else { ?>
      <p><?php echo '"No result"; ?></p>
  <br />
  
  

  <?php } ?>
  <?php } ?>
  

i don know is this correct approach please help me

Newbie

Posts

Joined
Mon Jul 27, 2015 2:32 pm
Who is online

Users browsing this forum: No registered users and 31 guests