I have a model with two queries:
function listCategories()
{
$result=$this->db->query("select * from table")->result();
return $result;
}
function listSubCategories($var)
{
$result=$this->db->query("select * from table where field=$var")->result();
return $result;
}
Then i call the first function on my controller:
$data['rows']=$this-开发者_Python百科>my_model->listCategories();
The problem is: now i need to call the second function (listSubCategories()) and the $var that i need to pass to it, is a field from the database which is returned by the listCategories() function
What's the best way to handle a situation like this?
Thanks in advance.
Just pass the return from the first function into your call for the second function:
$data=$this->my_model->listCategories();
$sub=$this->my_model->listSubCategories($data->row()->field_name);
精彩评论