I work with PHP in Codeigniter and even more recent. I am stuck in a problem in the last 2 days.
I have a page for displaying lists of events that are retrieved from the database and displayed using a loop. I have done this successfully. Now I want to give the opportunity to edit or delete individual events that should make changes to db. For this, I use 2 buttons; edit and delete. Please note that they are all in one cycle and, thus, the same buttons are repeated in each event (element). When you click on the button, a modal will appear. For example, when you click the Delete button, a modal prompt appears to confirm the deletion. DELETE in this modal mode, send my form and the function of the call controller, which should delete the corresponding record in the database.
How can I identify the identifier of this particular element so that I can remove or update it? I get the identifier of the first element always.I referred to this: passing php variable to modal window with click function
But I could not connect them with my problem.
Here is my view:
<ul class="timeline">
<?php
if(isset($eventlist)){
foreach ($eventlist as $events) {
<li class="yellow timeline-noline' >
<div class="timeline-time">
<span class="date" id="date" >
<?php if(!empty($events->event_date)){echo $events- >event_date ;} ?> </span>
<span class="time" id="time" >
<?php if(!empty($events->event_time)){echo $events->event_time ;}?> </span>
</div>
<div class="timeline-icon">
<i class="icon-trophy" style="margin-top:12px;"></i>
</div>
<div class="timeline-body">
<div>
<button type="button" title="Remove" id="remove" name="remove" href="#portlet-remove" data-toggle="modal" style="float:right;background-color: transparent;border: 0px;" ><i class="fa fa-trash-o"></i></button>
<button type="button" title="edit" id="edit" name="edit" href="#portlet-edit" data-toggle="modal"style="float:right;background-color: transparent;border: 0px;" ><i class="fa fa-pencil-square-o"></i></button>
<h2 id="title" ><?php if(!empty($events->event_title)){echo $events->event_title ;}?></h2>
</div>
<div class="timeline-content">
<img class="timeline-img pull-left" src="<?php echo $this->config->base_url(); ?>assets/admin/pages/media/blog/2.jpg" alt="">
<span id="desc" > <?php if(!empty($events->event_desc)){echo $events->event_desc ;}?> </span>
</div>
<div class="timeline-footer">
<a href="javascript:;" class="nav-link pull-right">
</a>
</div>
</div>
</li>
<?php
} } ?>
</ul>
source
share