dongtan2017 2016-11-22 18:42
浏览 92
已采纳

多选复选框以显示表记录

I want to filter the table by using multiple select checkbox by selecting multiple Company Name and the table will display the record related to the selected checkbox. It only able to select one checkbox and display one related record only but it cannot multiple select checkbox.

<form name="frmSearch" id="frmSearch" method="post" action="">

  <label>Company Name&nbsp;</label>
  <select id="multiple-checkboxes" multiple="multiple" name="COMPANYNAME">
    <?php
        $query = mysqli_query($conn_connection, "SELECT * FROM sl_iv GROUP by COMPANYNAME");

        while ($row = mysqli_fetch_assoc($query)) {
            echo "<option value='".$row["COMPANYNAME"]."'".($row["COMPANYNAME"]==$_POST["COMPANYNAME"] ? " selected" : "").">".$row["COMPANYNAME"]."</option>";
        }
    ?>
  </select>
  <br></br>

  <button type="submit" id="submit" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-search"></span> Search</button>
  <a href="cust_due_list.php">
    <button type="button" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-refresh"></span> RESET</button>
  </a>

  <br></br>

  <table id="table">
    <center>
      <thead>
        <tr class="item-row">
          <th width="15%" style="text-align:center"><span>Doc No.</span></th>
          <th width="10%" style="text-align:center"><span>Due</span></th>
          <th width="5%" style="text-align:center"><span>Age</span></th>
          <th width="20%" style="text-align:center"><span>Customer Name</span></th>
          <th width="10%" style="text-align:center"><span>Ammount</span></th>
          <th width="10%" style="text-align:center"><span>Payment</span></th>
          <th width="10%" style="text-align:center"><span>OutStanding</span></th>
        </tr>
      </thead>
    </center>

    <tbody>
      <?php
                    if(isset ($_POST['COMPANYNAME']))
                    {
                        $COMPANYNAME = $_POST['COMPANYNAME'];
                        $fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME = '".$COMPANYNAME."' or sl_iv.DOCDATE <= '".$from."'";
                        $result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>
Query: $fetch");
                    }
                    if (mysqli_num_rows($result) > 0) {
                        // output data of each row
                        while($row = mysqli_fetch_assoc($result)) {

                        $docamt = $row['DOCAMT']; 

                    ?>
        <tr class="item-row">
          <td>
            <input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DocNo" id=DocNo0 " name="DocNo " value="<?php echo htmlspecialchars($row[ 'DOCNO']);?>" readonly></td>
          <td>
            <input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DueDate" id="DueDate0" name="DueDate" value="<?php echo htmlspecialchars($row['DUEDATE']);?>" readonly>
          </td>
          <td>
            <input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DateAge" id="DateAge0" name="DateAge" value="<?php echo $dateage;?>" readonly>
          </td>
          <td>
            <input type="text" style="text-align:center; font-size:15px" class="form-control input-sm CompanyName" id="CompanyName0" name="CompanyName" value="<?php echo htmlspecialchars($row['COMPANYNAME']);?>" readonly>
          </td>
          <td>
            <input type="text" style="text-align:right; font-size:15px" class="form-control input-sm TotalAmt" id="TotalAmt0" name="TotalAmt" value="<?php echo htmlspecialchars($row['DOCAMT']);?>" readonly>
          </td>
          <td>
            <input type="text" style="text-align:right; font-size:15px" class="form-control input-sm payment" id="payment0" name="payment" value="<?php echo htmlspecialchars($row['PAYMENTAMT']);?>" readonly>
          </td>
          <td>
            <input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Total_Outstanding" id="Total_Outstanding0" name="Total_Outstanding" value="<?php echo number_format((float)$outstanding, 2, '.', '');?>" readonly>
          </td>
        </tr>
        <?php
                        }
                    } else {
                        echo "0 results";
                    }
                    ?>

    </tbody>
  </table>
</form>



<script type="text/javascript">
  $(document).ready(function() {
    $('#multiple-checkboxes').multiselect();
  });

</script>
  • 写回答

1条回答 默认 最新

  • drn9573 2016-11-22 19:35
    关注

    When you receive multiple-select POST it cames as array, so you should use "IN" operator in your mysql request instead of comparison. Try to change one part of your code:

    if(isset ($_POST['COMPANYNAME'])) {
       $COMPANYNAME = $_POST['COMPANYNAME'];
       $COMPANYNAME = is_array($COMPANYNAME) ? $COMPANYNAME : [$COMPANYNAME];
    
       $companiesParam = '\''. join("', '", $COMPANYNAME) . '\'';
       $fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME IN (".$companiesParam.") or sl_iv.DOCDATE <= '".$from."'";
       $result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>
    Query: $fetch");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥30 itest不允许查看成绩怎么办
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏