I want to update database and add slug to every row. Problem is the code i wrote only update 1 row.
here is the structure of database
site_id integer primarykey autoincrement
site_title varchar
slug varchar
this is my controller here i make slug from title i get from database and want to update all row and insert new slug to every row
PHP Code:
public function ghjk(){
$this->load->helper('text');
$this->load->model("model_get");
$results= $this->model_get->getalltitles();
foreach ($results as $key) {
# code...
$page_title=$key['site_title'];
$cleanslug = convert_accented_characters($page_title);
$slug["slug"] = url_title($cleanslug,'-',TRUE);
$data["id"] = $key['site_id'];
echo $slug["slug"];
echo $data["id"];
}
$this->load->model("model_get");
$this->model_get->updateall($data,$slug);
}
this is my model
PHP Code:
function updateall($data,$slug){
$mdata = array(
array(
'site_id' => $data['id'] ,
'slug' => $slug['slug']
),
);
$this->db->update_batch('newsites', $mdata, 'site_id');
}