• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting table records

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.

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

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.

You are welcome - no time wasted Wink

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.