Updating/deleting 表中的行 (codeigniter)
Updating/deleting rows from tables (codeigniter)
我正在尝试(但没有成功)update/delete 行 table。
注意:我的数据库名称是"desafio"和table"materias"包含:(id,carrera_id(是"id"列的外键table "carreras") nombre, descripcion, carga_horaria)
我在分别单击按钮 "edit" 和 "delete" 时遇到了这 2 个错误:
I cannot upload the image
I cannot upload the image2
这是索引文件:
<tbody>
<?php
foreach($records as $record) {
echo "<tr>
<td>".$record->id."</td>
<td>".$record->carrera."</td>
<td>".$record->nombre."</td>
<td>".$record->descripcion."</td>
<td>".$record->carga_horaria."</td>
<td align='center'>
<a href='".site_url('Home/edit')."/$record->id'>
<button type='button' class='btn btn-primary'>EDITAR</button></a> |
<a href='".site_url('Home/delete')."/$record->id'>
<button type='button' class='btn btn-danger'>BORRAR</button></a>
</tr>";
}
?>
这是控制器文件(具有编辑、保存、更新和删除功能)
public function edit($id){
$data['record']=$this->Crudmodel->get_row_id($id);
$this->load->view('editar', $data);
}
public function saveupdate(){
$txtcarr=$this->input->post("txtcarr");
$txtmat=$this->input->post("txtmat");
$txtdesc=$this->input->post("txtdesc");
$txtcarga=$this->input->post("txtcarga");
$this->Crudmodel->save($txtcarr,$txtmat,$txtdesc,$txtcarga);
redirect('Home/index');
}
public function delete($id){
$this->db->where('id',$id);
$this->db->delete('desafio');
redirect('Home/index');
}
crudmodel(函数get_row_id)
public function get_row_id($id){
$this->db->where('id',$id);
$query=$this->db->get('id');
return $query->row();
}
以及允许我更正所写信息的文件"editar":
</head>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 align="center">UPDATE SUBJECTS</h2>
<form method="post" action='<?php echo site_url('Home/saveupdate'); ?>'>
<tr>
<td>
<select name="txtcarr">
<?php foreach($carreras as $item):?>
<option value="<?php echo $item->id;?>"><?php echo $item->nombre;?></option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr>
<td>Materia : </td>
<td><input type="text" name="txtmat" value="<?php echo $record->nombre ?>"/></td>
</tr>
<tr>
<td>Descripcion : </td>
<td><textarea name="txtdesc" value="<?php echo $record->descripcion ?>"></textarea></td>
</tr>
<tr>
<td>Carga horaria : </td>
<td><input type="text" name="txtcarga"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="save"/></td>
</tr>
<table class="table table-hover" align="center" border="0" cellspacing="0" cellpadding="0" width="300">
</table>
</div>
</div>
</div>
不明白是怎么回事:S
在你的 delete
函数中你不应该使用 table 名称吗?
$this->db->delete('materias');
我正在尝试(但没有成功)update/delete 行 table。
注意:我的数据库名称是"desafio"和table"materias"包含:(id,carrera_id(是"id"列的外键table "carreras") nombre, descripcion, carga_horaria)
我在分别单击按钮 "edit" 和 "delete" 时遇到了这 2 个错误:
I cannot upload the image
I cannot upload the image2
这是索引文件:
<tbody>
<?php
foreach($records as $record) {
echo "<tr>
<td>".$record->id."</td>
<td>".$record->carrera."</td>
<td>".$record->nombre."</td>
<td>".$record->descripcion."</td>
<td>".$record->carga_horaria."</td>
<td align='center'>
<a href='".site_url('Home/edit')."/$record->id'>
<button type='button' class='btn btn-primary'>EDITAR</button></a> |
<a href='".site_url('Home/delete')."/$record->id'>
<button type='button' class='btn btn-danger'>BORRAR</button></a>
</tr>";
}
?>
这是控制器文件(具有编辑、保存、更新和删除功能)
public function edit($id){
$data['record']=$this->Crudmodel->get_row_id($id);
$this->load->view('editar', $data);
}
public function saveupdate(){
$txtcarr=$this->input->post("txtcarr");
$txtmat=$this->input->post("txtmat");
$txtdesc=$this->input->post("txtdesc");
$txtcarga=$this->input->post("txtcarga");
$this->Crudmodel->save($txtcarr,$txtmat,$txtdesc,$txtcarga);
redirect('Home/index');
}
public function delete($id){
$this->db->where('id',$id);
$this->db->delete('desafio');
redirect('Home/index');
}
crudmodel(函数get_row_id)
public function get_row_id($id){
$this->db->where('id',$id);
$query=$this->db->get('id');
return $query->row();
}
以及允许我更正所写信息的文件"editar":
</head>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 align="center">UPDATE SUBJECTS</h2>
<form method="post" action='<?php echo site_url('Home/saveupdate'); ?>'>
<tr>
<td>
<select name="txtcarr">
<?php foreach($carreras as $item):?>
<option value="<?php echo $item->id;?>"><?php echo $item->nombre;?></option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr>
<td>Materia : </td>
<td><input type="text" name="txtmat" value="<?php echo $record->nombre ?>"/></td>
</tr>
<tr>
<td>Descripcion : </td>
<td><textarea name="txtdesc" value="<?php echo $record->descripcion ?>"></textarea></td>
</tr>
<tr>
<td>Carga horaria : </td>
<td><input type="text" name="txtcarga"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="save"/></td>
</tr>
<table class="table table-hover" align="center" border="0" cellspacing="0" cellpadding="0" width="300">
</table>
</div>
</div>
</div>
不明白是怎么回事:S
在你的 delete
函数中你不应该使用 table 名称吗?
$this->db->delete('materias');