开发者

Codeigniter query and structure

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜