【问题标题】:How to input the value of an array to my database如何将数组的值输入我的数据库
【发布时间】:2017-09-06 19:02:46
【问题描述】:

我设计了一个进入我的数据库的 html 输出表来从中挑选出它的值,我还包括提交按钮供用户从值数组中选择,这里是 sql 表

这是我用来输出表格的代码

 <table class="table table-hover mails m-0 table table-actions-bar">
     <thead>
         <tr>
             <th>Level</th>
             <th>Amount</th>
             <th>Potential Earning</th>
             <th>Action</th>
         </tr>
     </thead>
     <tbody>
         <?php
             for ($i = 0; $i < count($levels); $i++) {
             $level = $levels[$i];
         ?>
         <tr>
             <td>
                 <?php echo ($level->getLevel()); ?>
             </td>
             <td>
                 <?php echo ($level->getAmount()); ?>
             </td>
             <td>
                 <?php echo ($level->getPotentialEarning()); ?>
             </td>
             <td>
                 <button type="submit" value="Add Project" style="background-color:steelblue; color:white">Add Project</button>
             </td>
         </tr>
     <?php
         }
     ?>
     </tbody>
 </table>

但是,唯一的问题是添加项目按钮如何能够将实际数量提交到用户数据库,请帮助

【问题讨论】:

    标签: javascript php mysql arrays


    【解决方案1】:

    只需将金额解析为附加到按钮的链接。如果您决定不使用表单,此方法将起作用。如果您决定使用表单,只需添加一个名为 amount 的隐藏输入字段并在那里解析值

     <table class="table table-hover mails m-0 table table-actions-bar">
     <thead>
     <tr>
     <th>Level</th>
     <th>Amount</th>
     <th>Potential Earning</th>
     <th>Action</th>
     </tr>
     </thead>
     <tbody>
     <?php
     for ($i = 0; $i < count($levels); $i++) {
     $level = $levels[$i];
     ?>
     <tr>
     <td>
     <?php echo ($level->getLevel()); ?>
     </td>
     <td>
     <?php echo ($level->getAmount()); ?>
     </td>
     <td>
     <?php echo ($level->getPotentialEarning()); ?>
     </td>
     <td>
     <a type="submit" href="script.php?amount=<?php echo ($level->getAmount()); ?>" class="btn btn-default" value="Add Project" style="background-color:steelblue; color:white">Add Project</button>
     </td>
     </tr>
     <?php
      }
     ?>
     </tbody>
     </table>
    

    在您的 php 保存时,您可以检查为:

    if(isset($_GET['amount']) && is_numeric($_GET['amount'])){
      $amount = $_GET['amount'];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 2015-06-18
      • 2012-12-14
      • 2017-05-17
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多