Q:

Unable to pass variable from one function to another function in php

This is what I'm tying to do.
(When I refer to state and city. I literally mean US states and cities, New York, Texas etc...)
In order for me to display similar dealers on every dealership page I'm going to have to use the state and city variables. In my original function I'm passing the city variable but not the state variable. I've extracted the state variable via a function I've made (syntax below) but this is where I'm running into trouble.
When I extract the state I'm attempting to convert it as a variable but it's not working (syntax below). My question is, how would I convert what I'm extracting (the state) to a variable? 
In the below function I'm getting the state from the id that I'm passing. 
function get_state_from_the_id($id)
{
   $this->db->select('state');
   $this->db->where('id',$id);
   $result = $this->db->get('dealers');

   if ($result->num_rows() > 0){
      return FALSE; 
   } else {
      return TRUE; 
   }
}

This is where I'm running into trouble
$state = $this->Dealer_data->get_state_from_the_id($id); // gets the state

In the above line of code I'm attempting to extract the state as a variable from my function but it's not working. My objective is to extract the state (IE, new york, texas, california etc...) and insert that variable into another function I made. What am I doing wrong? How can I correct my mistakes? 
Thanks

A:

You have to return the $result:
if ($result->num_rows() > 0){
    return $result; 
} else {
    return FALSE; 
}

A:

This is my practice to provide your reference
Model
function get_state_from_the_id($id) {
  $query = $this->db->get_where('dealers', array('id' => $id));
  return $query->num_rows();
}

Contoller
$state = ($this->Dealer_data->get_state_from_the_id($id) > 0) ? FALSE : TRUE;

