使用PHP单击按钮时如何获取相同的行数据? [英] How to get same row data when click on button using PHP?

查看:81
本文介绍了使用PHP单击按钮时如何获取相同的行数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PHP从数组中获取一行数据。这是我的代码:

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.

推荐答案

您可以像

<?php
echo $v['whatever_your_primary_key_is'];
?>

然后在模态上,获取该ID并执行查询以获取当前详细信息,您将需要可以将这些详细信息解析为模态视图中html表单上的值

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

为避免再次使用数据库,只需回显primary的值即可。但是,请确保您仍处于同一循环中,以便能够获取当前值。因此,您的模态也必须处于同一循环中

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

尝试:

<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>

这篇关于使用PHP单击按钮时如何获取相同的行数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆