classes: GetValClass.php
if (!defined('_PS_VERSION_')) { exit; } class GetVal { protected $module = false; protected $name_of_class; protected $context; public function __construct(Module $module = null) { $this->name_of_class = get_class($this); $this->module = $module; $this->context = Context::getContext(); } public function value($filter) { if (!$filter) {return;} $sql = new DbQuery(); $sql->from('ps_table'); $sql->select('id_name'); $sql->where('id_addr = '.$filter); return Db::getInstance()->executeS($sql); } }
your module:
if (!defined('_PS_VERSION_')) { exit; } require_once(dirname(__FILE__).'/classes/GetValClass.php'); class myModule extends Module { public function __construct() { .... } public function getValueInMyClass() { $ddb = new GetVal($this); $filter = addslashes("'some street 10'"); $result = $ddb->value($filter ); $idsName = array(); if ($result) { foreach ($result as $data){ $idsName[] = $data['id_name']; } if ($idsName){ echo implode(', ',$idsName); } } } }