簡體   English   中英

如何從表單元格值設置 select 選項並在另一個 html 表中顯示數據庫行值 rest

[英]How to set select option from table cell value and display rest of database row value in another html table

我有一個包含項目、描述和價格表的報價,我想從數據庫 select 中獲取項目 select 並在其他表中顯示項目的描述和價格。

我是 PHP 的新手,有人可以幫忙嗎?

                 <td>
                    <span contenteditable>
                       <div class="productSelect">
                          <select name="customer" id="customer">
                             <option value="" disabled selected>Click to See Products</option>
                             <?php
                                $records = mysqli_query($conn, "SELECT id, name, sku, inventory_asset_acc, description, price_rate, cost, tax, quantity FROM addproducts");
                                    while($data = mysqli_fetch_array($records))
                                                    {
                                  
                                 echo '<option value="'.$data['id'].'" data-sku="' . $data['sku'].'" data-price_rate="' . $data['price_rate'].'" data-description="' . $data['description'] . '" data-quantity="' . $data['quantity'].'" >' . $data['name']. '</option>';
                                    
                                ?>
                              <?php } ?>
                          </select>
                           
                       </div>
                    </span>
                 </td>
                 <!------ Description -------->
                  
                 <td >
                     
                     <input style="width: 450px;" name="description" id="description" placeholder="&nbsp;"/>
                    <span contenteditable>
                    
                     
                     </span>
                 </td>
                  
                 <!------ Rate -------->
                 <td><span data-prefix id="price_rate" ></span><span  contenteditable></span></td>

我找到了解決方案:

PHP 和 HTML。

<!------ Item -------->
  <td>
   <span contenteditable>
    <div class="productSelect">
    <select name="table_info" id="table_info">
    <option value="" disabled selected>Click to See Products</option>
    <?php
    $records = mysqli_query($conn, "SELECT id, name, sku, inventory_asset_acc, description, price_rate, cost, tax, quantity FROM addproducts");
   while($data = mysqli_fetch_array($records))
   {
                                  
  echo '<option value="'.$data['name'].'" data-sku="' . $data['sku'].'" data-price_rate="' . $data['price_rate'].'" data-description="' . $data['description'] . '" data-quantity="' . $data['quantity'].'" >' . $data['name']. '</option>';
                                        
                                ?>
                              <?php } ?> 
                          </select>
                           
                       </div>
                    </span>
                 </td>
                 <!------ Description -------->
                  
                 <td>
                    <span contenteditable id="description">
                     </span>
                 </td>
                  
                 <!------ Rate -------->
                 <td> 
                     <span data-prefix >R</span><span contenteditable id="price_rate"></span>
                  </td>

還有我的 JavaScript:

<script>
             
             var mySelectTwo = document.getElementById("table_info");
             
             mySelectTwo.addEventListener("change", function() {
                     
             var myNewOption = mySelectTwo.options[mySelectTwo.selectedIndex].getAttribute("data-price_rate");
             document.getElementById('price_rate').innerHTML = myNewOption;
                 
             var myNewOption = mySelectTwo.options[mySelectTwo.selectedIndex].getAttribute("data-description");
             document.getElementById('description').innerHTML = myNewOption;
                     
                     
             });

暫無
暫無

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

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