Welcome Guest, Not a member yet? Register   Sign In
Foreach and updating routes via Mysql
#1

[eluser]mattnewark[/eluser]
Sorry posted in wrong forum, I have created another one in General.

Model
Code:
function update_routes()
    {
            $this->db->select("*");
            $query = $this->db->get("articles");
            foreach ($query->result() as $r)
                {
                    $data = '$route["' . $r['link'] . '"] = "' . $r['route'] . '";';
                    write_file(APPPATH . 'cache/routes.php', $data);
                }                
    }
Controller
Code:
function update_routes()
    {
       $this->articles_model->update_routes();
       redirect('admin/articles', 'refresh');
    }


Can someone please tell me what I am doing wrong, I know it is going to be something stupid but I think I have been looking at it for so long I am unable to see the mistake. When I run the above function, instead of it running through all the database rows and entering them into the file it is only adding the last row into the file.

Can someone please tell what I am doing wrong.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB