未根据行表从数据库中获取 ID

阿达马克马尔

为什么单击时无法从表中的行中获取 IDPending

这是代码:

<!-- ############################################################################################################################################################################################################ -->
<!-- TABLE BUSINESS -->
<div class="row" id="TblBiz" style="display: none;">
            <div class="col" style="height: 71px;">
                <h1 style="font-family: Roboto, sans-serif; font-weight: 300;">Business</h1>
            </div>
                <div class="col-md-8 offset-md-2">
                <div class="panel" id="main">
                    <div class="container-fluid container-bg">
                        <div class="table-responsive">
                            <table id="myTable4" class="table table-hover table-dark" style="font-size:11px; margin-top:6px;">
                                <thead style="font-size: 18px;">
                                    <th>#</th>
                                    <th>Business ID</th>
                                    <th>Name</th>
                                    <th>Owner</th>
                                    <th>View</th>
                                    <th>Approval</th>
                                </thead>
                                <tbody>
                                    <?php
                                    $sql = "SELECT * FROM mechanic_business";
                                    $result = mysqli_query($connect, $sql);
                                    
                                        if(mysqli_num_rows($result) > 0){
                                    
                                        $i = 1;
                                    
                                        while ($row = mysqli_fetch_assoc($result)) {
                                            $biz_ID = $row['businessID'];
                                            $mech_ID = $row['mechID'];
                                            $mech_name = $row['mech_name'];
                                            $bizName = $row['business_name'];
                                            $bizApprove = $row['business_approval_status'];
                                            $bizStatus = $row['business_status'];
                                            // $dateJoin = $row['DATE_REGISTERED'];
                                            // $dateFormated = date("d M Y", strtotime($dateJoin));

                                            // Color class in PHP color(Pending, Approved, Banned)
                                            $color = ($bizApprove === 'Pending') ? '#f0ad4e' : (($bizApprove === 'Approved') ? '#28a745' : '#dc3545');

                                                echo "<tr style='font-size:18px;'>";
                                                echo "<td class='align-middle'>" . $i; $i++ . "</td>";
                                                echo "<td class='align-middle'>" . $biz_ID . "</td>";
                                                echo "<td class='align-middle'>". $bizName ."</td>";
                                                echo "<td class='align-middle'>". $mech_name ."</td>";
                                                echo "<td class='align-middle'><input type='button' name='view' value='view' id='". $biz_ID ."' class='btn btn-info btn-xs view_biz'></td>";
                                                echo "<td class='align-middle'><a role='button' class='approval-bton' id='". $biz_ID ."' style='color:". $color ."';>". $bizApprove ."</a></td>"; 
                                                echo "</tr>";
                                            }
                                        } else {
                                            echo "<tr>";
                                            echo "<td colspan='7' class='table-active align-middle'>No Record in Database</td>";
                                            echo "</tr>";
                                        }
                                    ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
              </div>
            </div>
<!-- ############################################################################################################################################################################################################ -->

<!-- ############################################################################################################################################ -->
<!-- UPDATE APPROVE STATUS MODAL -->
    <div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel"> Update Business Approval Status </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>

                <form action="" method="post" enctype="multipart/form-data">

                    <div class="modal-body">

                        <input type="text" name="businessID" id="" value="<?php echo $biz_ID; ?>">

                        <div class="form-group">
                            <div>
                                <small id="photoHelp" class="form-text text-muted"><span style="color: #FF0000;">*</span><em>320px x 320px is ideal dimension, Format: jpg, png, jpeg, and PDF only</em></small>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                        <button type="submit" name="updateApprove" class="btn btn-primary">Save Change</button>
                    </div>
                </form>

            </div>
        </div>
    </div>
<!-- ############################################################################################################################################ -->

当我从每一行单击 a时,它假设会根据数据库Pending获取它们,但是当我从每一行单击时,它们显示的结果与下面链接中的图片相同。IDID

https://drive.google.com/file/d/1IcfDUs3Q8Wl5vVO3KF793M5noTukLrCL/view?usp=sharing

它们都显示ORVA01BIZ-00000002但在数据库中第一行是ORVA01BIZ-00000001并且ORVA01BIZ-00000002是第二行并且继续。

古普雷特凯特

有非常简单的逻辑。

  1. 首先,您的模型不在循环中,因此如果您想从数据库中获取每个 id,则无法在模型中传递 $biz_ID。

当循环结束时,它只会打印模型中的最后一行 biz_id。

解决方案是: -

您必须在代码中进行的更改

如果您想获取每个 id,您必须做一件事

这是你的第二个 td :-

  1. echo "<td class='align-middle bizzid'>" . $biz_ID . "</td>";

在您的模型中,您必须粘贴以下内容:-

  1. <input type="text" name="businessID" id="businessID" value="">-

此 jquery 代码可以帮助您获得所需的结果。

 var bizid = $(this).closest('tr').find('.bizzid').text();
 $('#businessID').val(bizid);
 $('#approveModal').modal('show');
 });'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

根据内容查询获取sqlite数据库行的id

如何根据id从数据库中获取值

获取数据库中刚刚插入的行的id

从数据库中获取项目 ID

如何使用 bootstrap 和 Ajax 根据选定的 ID 从 MySQL 数据库中获取数据?

Android根据ListView ID从数据库获取单行

我需要使用表中的员工ID从mysql数据库中获取数据

根据 Laravel 数据库中的 user_id 获取城市值

根据数据库中的消息和线程 ID 获取图像列表

根据用户ID从数据库中获取用户角色

如何从数据库 X 中的表中删除行,其中 ID 存在于数据库 Y 中

如何从Codeigniter中的数据库表中获取偶数/奇数ID号

使用与数据库中正确的表行/人员/id 关联的 HTML 表中的链接

获取行以获取ID列表,其中MySQL数据库中特定字段最大

如何在Java代码中从数据库表获取最大ID

Laravel 5.2:数据库记录获取并检查另一个表中的ID

从具有多个表的SQL数据库中获取用户ID

根据ID锁定Access数据库中的先前记录

根据featherJs api中的自定义ID名称从mongo数据库中获取模型数据

根据唯一 ID 匹配将数据传输到外部 Excel 数据库表中

下一行或 id 从表和数据库中删除

如何设置列表项valuse属性以更正数据库表行中的ID?

MYSQL返回其他数据库表中不存在的行ID的列表

如何获取数据库中特定行的相应user_id(自动增量)值?

无法根据我的 ID 获取值获取所有数据库数据

数据库中每个表的最大ID

使用ID从数据库获取数据

Android-在数据库onItemClick中获取_id

在推送通知中获取数据库通知 ID