Make codeigniter 'table' row deletable on click.

ozzy t
ozzy t used Ask the Experts™
on
I added codeigniter 'table' to my project and i got desired outcome for view except for the fact that the way i had it before i was able to delete record by clicking on them since they were anchor tags, i would like to know how to recreate this in new table format. Thanks!
site_model.php
site.php
options_view.php
Capture2.PNG
Capture.PNG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Marco GasiFreelancer
Top Expert 2010

Commented:
Please, if the file is small don't post it: use 'code' tags and copey directly the file content within the tags so we can read it directly in the question page instead of downloading or open new tabs in our browsers.

That said, I would change your controller function this way:

	function delete($item_id)
	{
		$this->site_model->delete_row($item_id);
		$this->index();
	}

Open in new window


Then update your model function:
	function delete_row($item_id)
	{
		$this->db->where('id', $item_id);
		$this->db->delete('assets');
	}

Open in new window


This should work fine.
Marco GasiFreelancer
Top Expert 2010

Commented:
I see you don't have added the loading model statement as I suggested here: https://www.experts-exchange.com/questions/29039171/How-can-i-display-my-results-as-a-table-in-codeigniter.html#a42186996. Maybe your model is autoloaded?
ozzy tDeveloper/Health Informatics

Author

Commented:
Thank you for all your help and suggestions, i really appreciate it. i did as you suggested but nothing changed. Maybe i should be clearer in what i am trying to do, i would like to be able to click on record and have it delete , i had it like this before but it was not in table format ,so i would like to make the row an anchor tag that i can delete on click or have a button to delete record, again thank you for all your help and time.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Freelancer
Top Expert 2010
Commented:
Oh, sorry I didn't understand that :)
Ok, so you just have to modify options_view.php to build a table instead of a series of paragraphs:
<h2>Read</h2>
<table>
 <?php if(isset($records)) : foreach ($records as $row) : ?>   
<tr>
<td>
<?php echo anchor("site/delete/$row->Id", $row->title); ?> 
<td>
 <td><?php echo $row->content; ?> </td>   
</tr>

<?php endforeach; ?>
</table>

<?php else : ?>

<h2>No records returned.</h2>

<?php endif; ?>

Open in new window


To make your anchor like a button just use css: now I have to go, but I'll be happy to show you how to do it.
ozzy tDeveloper/Health Informatics

Author

Commented:
Thank You!!
Marco GasiFreelancer
Top Expert 2010

Commented:
Thanks for point ozzy. So this was a duplicate question for https://www.experts-exchange.com/questions/29039171/How-can-i-display-my-results-as-a-table-in-codeigniter.html?cid=1752... Please, close the other question wothout awarding point, just explaining that the answer is here (for people who can find that thread by googling

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial