Reputation: 131
i want to update and delete an entry im really new at this and i dont know where to put the function..so yeah i need help
controller
function delete()
{
$this->site_model->delete_row('booking');
$this->view();
}
}
site_model
function delete_row()
{
$this->db->where('id', $this->uri->segment(3));
$this->db->delete('booking');
}
and my view
<?php
$this->table->set_heading("Name","Nationality","Number of Guest","Date","Package","Other Request","Delete Record");
$qry = $this->db->get('booking');
foreach ($qry->result() as $row) {
$this->table->add_row($row->name,$row->nationality,$row->number_of_guest,$row->date,$row->package,$row->request);
}
echo $this->table->generate();
?>
TIA, im really new at this so please consider this..
Upvotes: 1
Views: 5579
Reputation: 37701
Since you have no real question, I'll just give you a few hints before we close this.
$this->load->view('view_name_here');
site.com/booking/delete/5
, where 5 is the id of the booking) using a simple anchor, JavaScript redirection, form submit, etc...The bottom line is: please use the tutorial, it's very good and covers 99% of what you'd need: http://ellislab.com/codeigniter/user-guide/tutorial/
UPDATE
You can build your own table for more flexibility (and you're probably more comfortable with HTML rather than CI's helper functions). So, every row would need a delete button/link like this:
<tr>
<td><?php echo $row->name; ?></td>
... etc
<td><a href="<?php echo base_url('booking/delete/' . $row->id); ?>">DELETE</a></td>
</tr>
Upvotes: 0
Reputation: 509
Try this:
You can pass parameters through the URL.. so, for example:
yoursite/index.php/controller/delete/12
The ID = 12
In your controller:
function delete($id=null)
{
$this->booking_model->delete($id);
$this->view('my_view_name');
}
booking_model
function delete($id)
{
$this->db->where('id', $id);
$this->db->delete('booking');
}
Upvotes: 1