开发者

Query not working in CodeIgniter

function menuName () 
{
    $this->viewData['page_title'] = "ContentManagement Systemt!";
    $this->db->where('visible', 1);
    $this->db->order_by("position", "ASC"); 
    $query = $this->db->get('subjects');
    $subjects = $query->result();
    foreach ($subjects as $subject)
    {
        echo $subject->menu_name ."<br />";
        $this->db->where('subject_id', $subject->id );
        $query = $this->db->get('pages');
        $pages = $query->result();
        foreach ($pages as $page)
        {
            echo $page->menu_name ."<br />";
        }        
    }
}

Why is my query not working?开发者_运维技巧 Please tell me.


You should always use foreach loops like the following:

$subjects = $query->result();
foreach ($subjects as $subject)

Your approach has a bad performance.

And maybe this already solves your problem - I couldn't test it right now . Your query variables are named equally and you're using $query in both of your foreach loops - this could maybe lead to some strange behaviour.


Why dont you echo the query like so:

echo $this->db->last_query()

To see what is going on with the results

Maybe the problem is there.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜