0

My target is to show an echo "No data" when the query result is empty. What happening currently is that when my query is empty, it shows an error. (Please see the picture below for the error) I provided my codes below and my screenshot. Any help will be appreciated. Thank you

enter image description here

Controller:

public function new1($arenaID=0) {
       
        $data['activeNav'] = "";
        $data['subnav'] = "arenas";
        $this->header($data);
        $this->nav();
        
        $data['k1']=$this->arenas->meron1();
       
        $this->load->view('new', $data);
        $this->footer();
       
    }

Model:

function meron1(){
      
        $query = $this->db->query("SELECT fightID FROM fight_entries where position='meron' ORDER BY fightID DESC LIMIT 1");  
        
            return  $query->row()->fightID+1;
          
        
         
    }

1 Answer 1

2

A better way to do this is just to check the number of rows being returned.

function meron1(){
 $query = $this->db->query("SELECT fightID FROM fight_entries where position='meron' ORDER BY fightID DESC LIMIT 1");
    if($query->num_rows() > 0){
     $query = $query->rows();
     return  $query->fightID+1;        
    }else{
    $message = "No Data";
    return $message;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, worked like a magic. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.