I need to fetch one row data from array using PHP. Here is my code:
<?php
if($bstatus==1) {
$bikeArr=$data['data'];
$count=1;
foreach ($bikeArr as $v) {
?>
<tr>
<td><?php echo $count++; ?></td>
<td><?php echo $v['book_date']; ?>, <?php echo $v['book_time']; ?></td>
<td><?php echo $v['book_id']; ?></td>
<td><?php echo $v['start_date']; ?>, <?php echo $v['start_time']; ?> /<br /> <?php echo $v['end_date']; ?>, <?php echo $v['end_time']; ?></td>
<td><?php echo $v['service_name']; ?> / <br /> <?php echo $v['model_name']; ?></td>
<td><?php echo $v['booking_status_str']; ?></td>
<td><a class="btn btn-xs btn-success" data-toggle="modal" data-target="#takemebookingsec">View Booking <i class="fa fa-arrow-circle-right"></i></a></td>
</tr>
<?php
}
}
?>
Here I need while user will click on View Booking button the exact same row index data will fetch from array and push into other variable.
You can parse the value of the primary key on the view booking button as in
<?php
echo $v['whatever_your_primary_key_is'];
?>
And then on the modal, get that id and do a query to get the current details You will need to parse these details as values of course on your html form in the modal view
To avoid using the database again, just echo the value of primary. But make sure you are still in the same loop to be able to get the current values. SO your modal must also be in the same loop
Try:
<a class="btn btn-xs btn-success" data-toggle="modal" data-target="#takemebookingsec<?= $v['your_primary_key_goes_here']; ?>">View Booking <i class="fa fa-arrow-circle-right"></i></a>
On your modal, still in the same loop,
<div class="modal fade" id="takemebookingsec<?=$v['your_primary_key_goes_here']; ?>">
<form>
<input type="text" name="name" value="<?= $v['what_ever_name']; ?>">
<!--Add other input here-->
</form>
</div>
Related
i have workers or employee table .. and i have Resign Date inside the table ..
and there is Edit Button, Replace Button and Delete button in every single data in table ..
Replace BUTTON is for replacing the new worker over the resigned worker.. and i already make the button disable when the resign date is empty and enable when it not empty .
now i don't know how can i make the button enable in next month of resign date.
for example :
if somebody resigns on 17/3/2021, the button should be disabled until 1/4/2021 (the first day of the next month) .. i hope someone can help me
here is my table :
$data = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC);
$kode=trim($data ['id_mcm']);
$kode_mcm=trim($data ['kode_mcm']);
$nama_mcm=trim($data ['nama_mcm']);
$kode_ctr=trim($data ['kode_ctr']);
$nama_ctr=trim($data ['nama_ctr']);
$no_ktp=trim($data ['no_ktp']);
$no_hp=trim($data['no_hp']);
$domisili=trim($data['domisili']);
$tgl_join=date_format($data ['tgl_join'],'d-m-Y');
if ($data ['tgl_resign']!=''){$tgl_resign=date_format($data ['tgl_resign'],'d-m-Y');
<!--i tried to added this code below so i can use if inside Replace button tag with less operation-->
$tgl_resign_baru=date_format($data ['tgl_resign'],'30-m-Y');
}else{$tgl_resign='';}
$alamat=trim($data['alamat']);
?>
<tr <?php if($tgl_resign!=''){echo 'style="background-color:#f2c4cd"';} else {echo'';}?>>
<td><?php echo ++$no_urut;?></td>
<td><?php echo $kode_mcm;?></td>
<td><?php echo $nama_mcm;?></td>
<td><?php echo $kode_ctr;?></td>
<td><?php echo $nama_ctr;;?></td>
<td><?php echo $no_ktp;?></td>
<td><?php echo $no_hp;?></td>
<td><?php echo $domisili;?></td>
<td><?php echo $tgl_join;?></td>
<td><?php echo $tgl_resign;?></td>
<td><?php echo $alamat;?></td>
<td>
and here is the Button tag :
<!-- button Modal replace-->
<button type="button" class="btn btn-success btn-xs" data-toggle="modal" data-target="#myy<?php echo $kode; ?>"
<?php if (($akses=="Leader" || $akses=="IT") && $tgl_resign!="" && $kode_mcm!=""
&& $tgl_resign>$tgl_resign_baru) <-- and i add this too . but it doesn't work
{
echo '';
}else{
echo 'disabled';}?>>
Baru
</button>
You can simplify this logic by setting the resign date to the the end of the month, and then comparing that to the current date. If it's greater than or equal to the current date you can disable the button.
<?php
$resignDate = '2021-03-17';
$resignDateEOM = date('Y-m-t', strtotime($resignDate)); //2021-03-31
$currentDate = date('Y-m-d');
if ($resignDateEOM >= $currentDate) {
echo 'resign date end-of-month is still in the future';
}
<?php
$disabled = '';
if (
($akses=="Leader" || $akses=="IT")
&& $tgl_resign!=""
&& $kode_mcm!=""
&& $resignDateEOM >= $currentDate
) {
$disabled = 'disabled';
}
?>
<button
type="button"
class="btn btn-success btn-xs"
data-toggle="modal"
data-target="#myy<?= $kode; ?>"
<?= $disabled; ?>
></button>
I have two tables users and posts where is the primary key is id. When i click on delete button, i want to post the id.
Here is my view:
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Title</th><th scope="col">Hit</th>
<th scope="col">Edit</th><th scope="col">Delete</th><th scope="col">Read More</th>
</tr>
</thead>
<tbody>
<?php foreach($posts as $post) : ?>
<?php if($this->session->userdata('username') == $_SESSION["username"]): ?>
<tr>
<td><?php echo $post['title']; ?> </td>
<td><?php echo $post['post_views']; ?></td>
<td><a class="btn btn-default" href="<?php echo base_url(); ?>posts/edit/<?php echo $post['slug']; ?>">Edit</a></td>
<td>
<?php echo form_open('/posts/delete/'.$post['id']); ?>
<input type="submit" value="Delete" class="btn btn-danger">
<input type="hidden" name="id" value="<?php echo $post['id'] ?>" />
</form>
</td>
<td><p><a class="btn btn-default" href="<?php echo site_url('/posts/'.$post['slug']); ?>">Read More</a></p></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
There are so many ways to do this, the best most common one is to get it from the url like this:
$id = #end($this->uri->segment_array());
Or this:
$id = $this->uri->segment(3);
Or you can do this by passing it in a hidden input like this:
<?php echo form_open('/posts/delete/'.$post['id']); ?>
<input type="submit" value="Delete" class="btn btn-danger">
<input type="hidden" name="id" value="<?php echo $post['id'] ?>" />
</form>
Or using ajax.
delete link with confimation
Delete
call delete method in js and then show confimation msg.
Why you are using form tag to call a function? You can do this with anchor tag easily and can pass id. This one line code will work perfectly
<td><a class="btn btn-danger" href="<?= site_url('posts/delete/'.$post['id']) ?>">Delete</a></td>
In controller delete function will be like this
public function delete($id){
echo $id;
}
I have this part of code in my view file:
<?php foreach ($posts as $post) { ?>
<tr>
<td><?php echo $post['id']; ?></td>
<td><?php echo $post['title']; ?></td>
<td><?php echo $post['content']; ?></td>
<td>
<div class="btn-group">
Edit
Delete
</div>
</td>
</tr>
<?php } ?>
Well .. how to send GET parameter with site_url function, this is my anchor part:
a href="<?php echo site_url('admin/blog/show'); ?>" class="btn btn-success">Edit</a>
where to send $post['id'] ?
I see some question in SO, but answers was with hardcode...
here we have a example
echo anchor('news/local/'. $post['id'], 'any text', array('title' => 'The best news!'));
In your controller you will get something like.
echo $this->uri->segment('3');
Also load url helper/library as well.
Should be like this :
Edit
The given code should be like this :
<?php foreach ($posts as $post) { ?>
<tr>
<td><?=$post['id']; ?></td>
<td><?=$post['title']; ?></td>
<td><?=$post['content']; ?></td>
<td>
<div class="btn-group">
Edit
Delete
</div>
</td>
</tr>
<?php } ?>
In your show method access post id like this :
public function show($post_id)
{
echo $post_id;
}
For more : https://www.codeigniter.com/user_guide/helpers/url_helper.html
EDIT: Solved by adding modal inside loop
Can someone explain to me how to access the foreach loop variable outside foreach?
<?php foreach($sup as $data){ ?>
<tr>
<td><i class="circular blue lock icon"></i><?php echo $data['id']; ?></td>
<td><div class="ui large green label">
Solved!
</div></td>
<td><?php echo $data['subject']; ?></td>
<td><?php echo $data['text']; ?></td>
<td><?php echo $data['date']; ?></td>
<td>
<div class="ui buttons">
<input type="hidden" name="id" value="<?php echo $data['id']; ?>" />
<input type="submit" name="cancel" value="Lock" class="ui button" tabindex="5">
<div class="or"></div>
<button id="sup" class="ui right labeled icon positive button">
Reply
</button>
</div>
</td>
</tr>
<?php } ?>
For example, I want to use $data['text'] in my modal.
Add the data attribute to your button:
<button data-text="<?php echo $data['text']; ?>" class="ui right labeled icon positive button">
Then, in your modal you can access it with Javascript, like so:
var text = document.getElementById('sup').dataset.text
Also, you can't use an unique id inside a foreach loop, otherwise it will be replicated along with the rest of the code. Remove the "id" field from your button.
New to Codeigniter and trying to teach myself by exploring and messing with InvoicePlane however i'm a bit stuck when it comes to this section.
I've got a controller which loops through a number of different styles. To sends it to index.php view and is displayed fine.
Each style might have a parent style and again I can display the parent style ID fine but i'm trying to get my head around how to get the name of each parent style from the ID.
For example, the view page is as follows:-
<?php foreach ($property_styles as $style) { ?>
<tr>
<td><?php echo $style->property_style_id; ?></td>
<td><?php echo ($style->property_style_group) ? lang('yes') : lang('no'); ?></td>
<td><?php echo $style_parent->property_style_name; ?></td>
<td><?php echo $style->property_style_name; ?></td>
<td class="text-right">
<a href="<?php echo site_url('property_styles/form/' . $style->property_style_id); ?>"
title="<?php echo lang('edit'); ?>"><i class="fa fa-edit orange fa-margin"></i></a>
</td>
</tr>
<?php } ?>
The third table cell hows - $style_parent->property_style_name which is where i'd like the name to appear. The value it needs to use to determine is $style->property_style_parent_id
Could someone help point me in the right direction?