Welcome Guest, Not a member yet? Register   Sign In
check for found results in controller
#1

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

Reply
#2

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

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 11-06-2021, 09:49 AM by ikesela.)

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

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




Theme © iAndrew 2016 - Forum software by © MyBB