Welcome Guest, Not a member yet? Register   Sign In
Deleting table records
#1

[eluser]ozy123[/eluser]
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.
#2

[eluser]LuckyFella73[/eluser]
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
Code:
<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
#3

[eluser]ozy123[/eluser]
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.
#4

[eluser]LuckyFella73[/eluser]
You are welcome - no time wasted Wink




Theme © iAndrew 2016 - Forum software by © MyBB