Javascript 如何通过选择特定id在表中显示数据以从数据库中获取多行

Javascript 如何通过选择特定id在表中显示数据以从数据库中获取多行,javascript,php,mysql,Javascript,Php,Mysql,我需要在表格中显示表格“.table table bordered”的多行,单击以获得特定id 我的问题很有效。但是我不知道如何在id的不同行中显示多个数据 那我需要什么 单击查看按钮后,表单模式将在输入字段中显示u\u lead\u编号,对于特定的lead\u编号,我需要在同一表单内的表视图中显示不同的产品详细信息 <div class="modal fade" id="modal-view-lead_creation" role="di

我需要在表格中显示表格“.table table bordered”的多行,单击以获得特定id

我的问题很有效。但是我不知道如何在id的不同行中显示多个数据

那我需要什么

单击查看按钮后,表单模式将在输入字段中显示
u\u lead\u编号
,对于特定的
lead\u编号
,我需要在同一表单内的表视图中显示不同的产品详细信息

<div class="modal fade" id="modal-view-lead_creation" role="dialog" aria-labelledby="modal-view-lead_creationTitle" aria-hidden="true">
    <div class="modal-dialog" style="width:1270px;" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h3 class="modal-title" id="modal-add-lead_creationTitle" align=center>View Lead Creation</h3>
                <br>
            </div>
            <div class="modal-body">
                <div class="panel-body pan">
                    <form name="view_lead_creation-form" id="view_lead_creation-form" method="POST" action="lead_status_transfer_update.php" autocomplete="off" enctype="multipart/form-data" class="form-separated">
                        <h4>Lead Details:</h4>
                        <br>
                        <div class="form-body pal">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group"><label class="control-label">LEAD NUMBER <span class='require'>*</span></label>
                                        <div class="input-icon right">
                                            <input type="text" id="u_lead_number" name="u_lead_number" placeholder="Lead Number" class="form-control form-rounded" disabled/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-body">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th class="success text-center">Sl.no<span class='require'>*</span></th>
                                            <th class="success text-center">Product<span class='require'>*</span></th>
                                            <th class="success text-center">Price<span class='require'>*</span></th>
                                            <th class="success text-center">Delete</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>1</td>
                                            <td><input type="text" name="ulead_product" id="ulead_product"  class="datepicker-default form-control form-rounded"/></td>
                                            <td><input type="text" name="ulead_price" id="ulead_price"  class="datepicker-default form-control form-rounded"/></td>
                                            <td><input type="text" name="ulead_qty" id="ulead_qty"  class="datepicker-default form-control form-rounded"/></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </form>
                </div>               
            </div>
        </div>
    </div>
</div>

<table class="table table-hover table-striped table-bordered" id="list_lead_creation_table" width="98%">
    <thead>
        <tr>
            <th >SL NO</th>
            <th >LEAD NUMBER</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th ></th>
            <th >LEAD NUMBER</th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <?php
              $query = "SELECT * FROM mgen_leadf_details";
              $data = mysqli_query($conn, $query) or die('error2');
              if(mysqli_num_rows($data) > 0){
                  while($row = mysqli_fetch_assoc($data)){
            ?>
            <?php
              $lead_create_querys = "SELECT mgen_leadf_products.lead_product AS product,  mgen_leadf_products.lead_price AS price, mgen_leadf_products.lead_quantity AS quantity WHERE lead_num = '".$row['lead_num']."'";
              $create_datas = mysqli_query($conn, $lead_create_querys) or die('error5');
              if(mysqli_num_rows($create_datas) > 0){
                  while($lead_created_rows = mysqli_fetch_assoc($create_datas)){
            ?>
            <td>
                <button type="button" data-target="#modal-view-lead_creation" 
            onclick="set_ulead_creation_details('<?php echo $row['lead_num'];?>','<?php echo $lead_created_rows['product'];?>','<?php echo $lead_created_rows['price'];?>','<?php echo $lead_created_rows['quantity'];?>');" data-toggle="modal" class="btn btn-primary form-rounded"> <i class="fa fa-edit"></i>View</button>
            </td>
            <?php }
            }?>
            <?php }
            }?>
        </tr>
    </tbody>
</table>

<script>
function set_ulead_creation_details(ulead_num_id, ulead_product, ulead_price,
    ulead_qty)
{
    $("#u_lead_number").val(ulead_num_id);
    $("#uproduct_id").val(ulead_product);
    $("#ulead_price").val(ulead_price);
    $("#ulead_qty").val(ulead_qty);
}
</script>

&时代;
查看潜在客户创建

潜在客户详细信息:
潜在客户数* 序号* 产品* 价格* 删除 1. SL号 潜在客户数 潜在客户数
首先,在你的方法中你有一个选择N+1的问题。查询应将products表连接到details表,如下所示:

SELECT p.lead_num, p.lead_product AS product, p.lead_price AS price, p.lead_quantity AS quantity
FROM mgen_leadf_details d
         JOIN mgen_leadf_products p ON d.lead_num = p.lead_num
然后,您必须比现在迭代一个级别:

<?php while($lead_created_rows = mysqli_fetch_assoc($create_datas)) : ?>
   <tr>
     <td>
            <button type="button" data-target="#modal-view-lead_creation" 
            onclick="set_ulead_creation_details('<?php echo $lead_created_rows['lead_num'];?>','<?php echo $lead_created_rows['product'];?>','<?php echo $lead_created_rows['price'];?>','<?php echo $lead_created_rows['quantity'];?>');" data-toggle="modal" class="btn btn-primary form-rounded"> <i class="fa fa-edit"></i>View</button>
        </td>
   </tr>
<?php endwhile; ?>


首先,在你的方法中你有一个选择N+1的问题。查询应将products表连接到details表,如下所示:

SELECT p.lead_num, p.lead_product AS product, p.lead_price AS price, p.lead_quantity AS quantity
FROM mgen_leadf_details d
         JOIN mgen_leadf_products p ON d.lead_num = p.lead_num
然后,您必须比现在迭代一个级别:

<?php while($lead_created_rows = mysqli_fetch_assoc($create_datas)) : ?>
   <tr>
     <td>
            <button type="button" data-target="#modal-view-lead_creation" 
            onclick="set_ulead_creation_details('<?php echo $lead_created_rows['lead_num'];?>','<?php echo $lead_created_rows['product'];?>','<?php echo $lead_created_rows['price'];?>','<?php echo $lead_created_rows['quantity'];?>');" data-toggle="modal" class="btn btn-primary form-rounded"> <i class="fa fa-edit"></i>View</button>
        </td>
   </tr>
<?php endwhile; ?>


它不像你建议的那样工作。你能在我的代码中编辑我的清晰理解吗。感谢您添加完整的代码,测试它,如果它仍然不工作,请在页面源代码中检查是否设置了
set\u ulead\u creation\u details
函数参数。它没有按照您的建议工作。你能在我的代码中编辑我的清晰理解吗。感谢您添加完整的代码,测试它,如果它仍然不起作用,请在设置了
set\u ulead\u creation\u details
函数参数的情况下签入页面源代码。您的代码易受SQL注入攻击。您应该使用准备好的语句。@Dharman举个例子,先生。
lead_num='“$row['lead_num']”。“
易受攻击。我不同意。虽然prepare语句是一种很好的做法,但在本例中,该字段是从其他表而不是从用户输入中获取的,因此它不易受到SQL注入的攻击。您的代码容易受到SQL注入的攻击。您应该使用准备好的语句。@Dharman举个例子,先生。
lead_num='“$row['lead_num']”。“
易受攻击。我不同意。尽管prepare语句是一种很好的做法,但在本例中,该字段是从其他表中获取的,而不是从用户输入中获取的,因此它不易受到SQL注入的攻击。