CodeIgniter Forums
check for found results in controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: check for found results in controller (/showthread.php?tid=80475)



check for found results in controller - Secux - 11-05-2021

How to check if there are results found with a model?

PHP Code:
$array = ['country_id' => $postData['country_id']];
$cities $this->CitiesModel->where($array)->orderBy('id''asc')->findAll();
if(
$cities){
// OK
} else {
// No results found




RE: check for found results in controller - InsiteFX - 11-06-2021

PHP Code:
if (isset($$cities)) {
    // ok
} else {
    // no data returned




RE: check for found results in controller - ikesela - 11-06-2021

Another option:
Code:
$result = $cities ?? null;

if($result){
  ... result found
}else{
  . ..result not found
}