sphway Posted August 19, 2022 Share Posted August 19, 2022 (edited) class GetVal{ public function value(){ $sql = new DbQuery(); $sql->from('ps_table'); $sql->select('id_name'); $sql->where('id_addr = some street 10'); return Db::getInstance()->execute($sql); // return ONE name } } I try to get the result in other class,but get nothing $ddb = new GetVal(); $result = $ddb->value(); Edited August 19, 2022 by sphway SOLVED (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted August 19, 2022 Share Posted August 19, 2022 (edited) Hi. execute = INSERT, UPDATE, DELETE, ALTER (not return) executeS = SELECT (return rows and all lines) GetValue = SELECT (return one) getRow = SELECT (return all rows and one line) Edited August 19, 2022 by 4you.software (see edit history) 1 Link to comment Share on other sites More sharing options...
ps8modules Posted August 19, 2022 Share Posted August 19, 2022 return Db::getInstance()->executeS($sql); 1 Link to comment Share on other sites More sharing options...
sphway Posted August 19, 2022 Author Share Posted August 19, 2022 30 minutes ago, 4you.software said: return Db::getInstance()->executeS($sql); thanks,but still not working,should i import the class GetVal ? Link to comment Share on other sites More sharing options...
ps8modules Posted August 19, 2022 Share Posted August 19, 2022 (edited) 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); } } } } Edited August 19, 2022 by 4you.software (see edit history) 1 Link to comment Share on other sites More sharing options...
sphway Posted August 19, 2022 Author Share Posted August 19, 2022 7 hours ago, 4you.software said: 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); } } } } Thanks,The issue is solved Link to comment Share on other sites More sharing options...
ps8modules Posted August 19, 2022 Share Posted August 19, 2022 I gladly helped. You can like posts. Just click on the gray heart under the posts. Please remember to include SOLVED in the subject title. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now