簡體   English   中英

將數組值插入HTML表的特定字段

[英]Insert array values into specific field of HTML table

我需要將pg_query選擇的值插入到表的特定字段中,並使用輸入type = text將其組織成數組:

 <tr> <td> <label for="street">Street:</label> </td> <td> <input type="text" placeholder="Street name" required="required" id="street" name="street" onchange="sendForm(this.form)"> </td> </tr> <tr> <td> <label for="building_no">Building No:</label> </td> <td> <input type="text" placeholder="Number of building (XXXX)" name="bld_no"> </td> </tr> <tr> <td> <label for="ID Sector">ID Sector:</label> </td> <td> <input type="text" placeholder="IotaNet Sector (5)" name="id_sector"> </td> </tr> 

所有值都是字符串,並且數組具有所有選定值:

 $qexist = "SELECT test.tb.street, test.tb.bld_no, test.tb.id_sector, FROM test.tb WHERE test.tb.street = '$street' AND test.tb.bld_no = '$bld_no' "; $ress = pg_query($qexist); while ($row = pg_fetch_array($ress)) { // values of $row[] have to be inserted into exact fields echo $row[1].'street'; echo $row[2].'bld_no'; echo $row[3].'id_sector'; ? ? ? ? ? ? var_dump($row); /* result of var_dump array(30) { [0]=> string(20) "90315464612890004 " ["id_bld"]=> string(20) "90315464612890004 " [1]=> string(50) "Street" ["street"]=> string(50) "Street" [2]=> string(4) "0004" ["bld_no"]=> string(4) "0004" [3]=> string(1) "5" ["id_sector"]=> string(1) "5"................ */ } 

請告知如何解決此問題。 我嘗試了不同的方法,但是盡管該站點顯示了echo和var_damp結果,但仍未成功,但這些字段仍然為空。 謝謝。

<input type="text" placeholder="Street name" required="required" id="street" name="street" value="<?php echo $row[1] ?>">

<input type="text" placeholder="Number of building (XXXX)" name="bld_no" value="<?php echo $row[2] ?>">

<input type="text" placeholder="IotaNet Sector (5)" name="id_sector" value="<?php echo $row[3]?>">

我已經通過實驗方法找到了解決方案,但是它是可行的。 我創建了新的變量數組$value[] ,為它們分配了$row[]值,代碼開始工作

 <?php> $qexist = "SELECT test.tb.id_bld, test.tb.street, test.tb.bld_no, FROM test.tb WHERE test.tb.street = '$street' AND test.tb.bld_no = '$bld_no' "; $ress = pg_query($qexist); while ($row = pg_fetch_array($ress)) { $value[0] = $row[0]; $value[1] = $row[1]; $value[2] = $row[2]; } ?> 

 <table> <tbody> <form method="get" action="t54646.php"> <tr> <td> <label for="id_bld">Building ID:</label> </td> <td> <input type="text" placeholder="Not for fill - system ordered" name="id_bld" value="<?php echo $value[0] ?>"> </td> </tr> <tr> <td> <label for="street">Street:</label> </td> <td> <input type="text" placeholder="Street name" required="required" id="street" name="street" onchange="sendForm(this.form)" value="<?php echo $value[1] ?>"> </td> </tr> <tr> <td> <label for="building_no">Building No:</label> </td> <td> <input type="text" placeholder="Number of building (XXXX)" name="bld_no" value="<?php echo $value[2] ?>"> </td> </tr> 

如果有人可以解釋為什么變量重命名后開始數組會起作用,這對許多人來說將是有用的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM