CodeIgniter Forums

Full Version: Deleting table records
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi guys,

Probably a dumb question but how do I pass values from a table to a controller via a delete button?

So I have a table in my view which retrieves values from the database and displays:

User Date
delete Jack 21/05/2012
delete john 20/05/2012

And I've added a delete button like so:

echo '<td align="center">' . "<a href='/codeigniter/auth/delete_avail/" . $date . "'>Delete</a>" . "</td>";

But I have no idea how to retrieve the date from the row to pass as the variable $date to the controller?

Thanks for any help.

El Forum

hi ozy123,

your table rows are generated via a loop I guess.
Whithin that loop you have 2 possibilities. The first
one is build the delete anchors like
<a href="&lt;?php echo base_url();?&gt;controller/delete/&lt;?php echo $row-&gt;id;?&gt;">delete</a>
The id would be the related id from your database row. In your controller method you
would make a delete function (or better in your model) using that id you
get from the URI segment.

The second way is to build a form in every singel row, storing the row->id
in a hidden input field. All forms would point to the same controller/method
where you read the id value via input->post('id') and delete the row that way.

Best regards

El Forum

oh! Of course. I'm real sorry for wasting your time. Long day yesterday brain must have just shutdown. Thanks for taking the time, appreciate it.

El Forum

You are welcome - no time wasted Wink