如何传递每个Php值到javascript URL(只显示1相同的行记录)

How to Pass every Php value to javascript URL (only showing 1 same row record)

本文关键字:显示 记录 何传递 Php 值到 URL javascript      更新时间:2023-09-26

以下编码需要帮助。然而,我得到了一些运行没有,当我按下编辑按钮时,它只显示运行没有'1',其他运行不像2或3也显示运行不1,当我按下编辑第2行和第3行。我在index.php文件中遇到了问题:

    <html>  
    <?php

                    $rb = $connect->Execute("SELECT * FROM IT_Dept.dbo.testingHeader A LEFT JOIN IT_Dept.dbo.testingDetail B 
                    ON A.invoiceno=B.invoiceno_dt
                    WHERE A.invoiceno = '".$search."'");

        }
                                     $invoiceno = $rb->Fields("invoiceno");
                                     $company = $rb->Fields("company");
                                     $custname = $rb->Fields("custname");


                                    $newadd=str_replace("<br />","'n",$custadd);
                                    //table details

                                    ?>

      <body>
    <?php 
    echo "<form id= 'form2' method='post'><table id='tabledesc' border=1>
                                <tr>
                                <th>Description </th>
                                <th>Qty</th>
                                <th >Unit Price(Before GST)</th>
                                <th>Total(Before GST)</th>
                                <th  >*Total GST</th>
                                <th  >Amount(RM)</th> 
                                <th  >Tax input/output</th>
                                <th  >Debit Acc</th>
                                </tr>";
    while(!$rb->EOF) {
     $description = $rb->Fields("description");
                                      $invoiceno_dt = $rb->Fields("invoiceno_dt");
                                      $runningno = $rb->Fields("runningno");
                                      $qty = $rb->Fields("qty");
                                       $unitprice = $rb->Fields("unitprice");
                                         $totalb4gst = $rb->Fields("totalb4gst");
                                         $gst = $rb->Fields("gst");
                                          $amount = $rb->Fields("amount");
                                         >Fields("creditacc");

                                      $description = $description->value;
                                    $invoiceno_dt = $invoiceno_dt->value;
                                    $runningno = $runningno->value;
                                    $qty = $qty->value;
                                    $unitprice = $unitprice->value;
                                    $totalb4gst = $totalb4gst->value;
                                    $gst = $gst->value;
                                    $amount = $amount->value;                               
    echo "<tr><td>".$description."</td>";
    echo "<td>".$qty."</td>";
    echo "<td>".$unitprice."</td>";
    echo "<td>".$totalb4gst."</td>";
    echo "<td>".$gst."</td>";
    echo "<td>".$amount."</td>";

    echo "<input type='hidden' name = 'runningno' id='runningno' value = ' $runningno ' >";
    echo "<td><button onclick='openedit()'>Edit</button></td>";
invoiceno_dt=".$invoiceno_dt."&runningno=".$runningno."'>Edit</a></td>";
invoiceno_dt=".$invoiceno_dt."&runningno=".$runningno."'>x</a></td><tr>";
    echo "<td><button onclick='opendelete()'>Delete</button></td>";
    $rb->MoveNext();
    }
    ?>
            </table></form></body>   
    <script type="text/javascript">
        var popup;

         function openedit() {

             var myinvoice = document.getElementById("invoiceno").value;
              var no = <?php echo $runningno; ?>;
            alert(no);
            popup = window.open("edit.php?invoiceno="+myinvoice+'&runningno='+no, "Popup", "width=500,height=600");
            popup.focus();
        }

            popup.focus();
        }

    </script>
    <?php
    $rb->close;
    $connect->close;

    ?>

您可以将运行编号添加到页面中,例如:

<script type="text/javascript">
    var no = <?php echo $runningNo; ?>;
</script>

试试这个

echo "<td><button onclick='"openedit('{$runningno}')'">Edit</button></td>";

除此之外,您最好删除输入字段中value属性中的空格。

echo "<input type='hidden' name='runningno' id='runningno' value ='$runningno' />";

按照建议使用模板文件

<html>
<!-- HTML code is here -->    
<input type='hidden' name = 'runningno' id='runningno' value = '<?php print $runningno; ?>'></input>
<!-- Some other html -->
<?php
//your php code here
?>
<!-- HTML again -->
</html>

html

内的js也是一样
<script type="text/javascript">
  var testJsValue = "<?php print $ValueFromPHP; ?>";
</script>

试试这个

echo '<td><button onclick="openedit('''.$runningno.''')">Edit</button></td>';