gpt4 book ai didi

javascript - 多选复选框ajax表过滤器

转载 作者:行者123 更新时间:2023-11-29 19:49:03 24 4
gpt4 key购买 nike

您好,之前我正在研究用于显示表记录的多个选择复选框,可以在 here 找到。现在我尝试使用 ajax 方法并删除提交按钮来更改前一个,当选择值而没有提交按钮时,它将过滤表。我的问题是使用 ajax 传递多个值。

index.php

            <script>
function getCOMPANY(val) {
$.ajax({
type: "POST",
url: "ajax.php",
data:'companyname='+val,
success: function(data){
$("#company-list").html(data);
}
});
}
</script>

<form name="frmSearch" id="frmSearch" method="post" action="">
<label>Client Name&nbsp;</label>
<select id="multiple-checkboxes" multiple="multiple" class="companyInput" onChange="getCOMPANY(this.value);" 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>
</form>

<div name="state" id="company-list" class="companyInput">
<table>
<center>
<thead>
<tr>
<th width="3%" style="text-align:center"><span></span></th>
<th width="20%" style="text-align:center"><span>Customer Name</span></th>
<th width="10%" style="text-align:center"><span>Terms</span></th>
</tr>
</thead>
</center>

<tbody>
<?php

if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {

$docno=$row['DOCNO'];
$cmpName=$row['COMPANYNAME'];

$m++;

?>
<tr data-toggle="collapse" data-target="#demo<?php echo $m?>" class="accordion-toggle">
<td><button class="glyphicon glyphicon-plus" type="button"><span class=""></span></button></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:center; font-size:15px" class="form-control input-sm terms" id="terms0" name="terms" value="<?php echo htmlspecialchars($row['terms']);?>" readonly></td>
</tr>

<tr>
<td></td>
<td colspan="10">
<div id="demo<?php echo $m?>" class="panel-collapse collapse">
<table class="table">
<tr style="background-color:#A9DC60; color:black;">

</tr>
<?php
$sql_1="SELECT * FROM `ar_iv` Inner Join `sl_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.`COMPANYNAME`='".$cmpName."' ";
$query_1 = mysqli_query($conn_connection, $sql_1);

while($DetRow = mysqli_fetch_assoc($query_1)) {
?>
<tr data-toggle="collapse" data-target="#demo<?php echo $m?>" class="accordion-toggle">
<td width="3%"><button class="glyphicon glyphicon-minus" type="button"><span class=""></span></button></td>
<td width="27%" style="text-align:center"><?php echo $DetRow['DOCNO'] ?></td>
<td width="10%" style="text-align:center"><?php echo htmlspecialchars($child['DOCAMT']); ?></td>
</tr>

<?php
}
?>
</table>
</div>
</td>
</tr>

<?php
}
}else {
echo "0 results";
}
?>

</tbody>
</table>
</div>

<script>
$(document).ready(function() {
$('#multiple-checkboxes').multiselect({
includeSelectAllOption: true
});
});
</script>

ajax.php

            <?php
session_start();
require_once('../include/mysqlconnection.php');
$m=0;//div collapse
$query = "SELECT * 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 GROUP BY COMPANYNAME";
$results = mysqli_query($conn_connection,$query);
?>

<body class="reports" onload="calculateSum()">

<table>
<center>
<thead>
<tr>
<th width="3%" style="text-align:center"><span></span></th>
<th width="20%" style="text-align:center"><span>Customer Name</span></th>
<th width="10%" style="text-align:center"><span>Terms</span></th>
</tr>
</thead>
</center>
<?php
if(!empty($_POST['companyname'])) {

$COMPANYNAME = $_POST['companyname'];
$COMPANYNAME = is_array($COMPANYNAME) ? $COMPANYNAME : [$COMPANYNAME];
$companiesParam = '\''. join("', '", $COMPANYNAME) . '\'';
$fetch = "SELECT * 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 COMPANYNAME IN (".$companiesParam.") GROUP BY COMPANYNAME";
$results = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");

}
if (mysqli_num_rows($results) > 0) {
while($row = mysqli_fetch_assoc($results)) {
$docno=$row['DOCNO'];
$cmpName=$row['COMPANYNAME'];

$m++;
?>
<tr data-toggle="collapse" data-target="#demo<?php echo $m?>" class="accordion-toggle">
<td><button class="glyphicon glyphicon-plus" type="button"><span class=""></span></button></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:center; font-size:15px" class="form-control input-sm terms" id="terms0" name="terms" value="<?php echo htmlspecialchars($row['terms']);?>" readonly></td>
</tr>

<tr>
<td></td>
<td colspan="10">
<div id="demo<?php echo $m?>" class="panel-collapse collapse">
<table class="table">
<tr style="background-color:#A9DC60; color:black;">

</tr>
<?php
$sql_1="SELECT * FROM `ar_iv` Inner Join `sl_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.`COMPANYNAME`='".$cmpName."' ";
$query_1 = mysqli_query($conn_connection, $sql_1);

while($DetRow = mysqli_fetch_assoc($query_1))
?>

<tr data-toggle="collapse" data-target="#demo<?php echo $m?>" class="accordion-toggle">
<td width="3%"><button class="glyphicon glyphicon-minus" type="button"><span class=""></span></button></td>
<td width="27%" style="text-align:center"><?php echo $DetRow['DOCNO'] ?></td>
<td width="10%" style="text-align:center"><?php echo htmlspecialchars($child['DOCAMT']); ?></td>
</tr>

<?php
}
?>
</table>
</div>
</td>
</tr>
<?php
}
}else {
echo "0 results";
}
?>
</table>

报告.php

            <?php
require_once('../include/mysqlconnection.php');
include("../include/mpdf/mpdf.php");
$m=0;

$COMPANYNAME = $_GET["COMPANYNAME"];
$terms = $_GET['terms'];

$item_q = "SELECT * From `sl_iv`";
if($COMPANYNAME!=""){

$item_q.= " WHERE COMPANYNAME = '".$COMPANYNAME."'";
}
if($terms != "")
{
$item_q.= " WHERE terms = '".$terms."'";
}
else{
$item_q.= " GROUP BY COMPANYNAME ";
}

$item = mysqli_query($conn_connection, $item_q);
//$mpdf=new mPDF('c','A4','','',32,25,47,47,10,10);

$mpdf = new mPDF(
'', // mode - default ''
'A4', // format - A4, for example, default ''
'', // font size - default 0

$stylesheet = file_get_contents('mpdf.css');
$mpdf->WriteHTML($stylesheet,1);

$header = '
<table>

</table>
';

$footer = '
';

$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);

$html = '
<style>
.gradient {
background-color: #F0FFFF;
}
</style>

<p align="center" style="font color: #191970; font-size:20px"><b>Customer</b></p>


<table width="100%" class="no-spacing" style=" vertical-align: middle; font color: #191970; font-family: serif; font-size: 9pt;">
<thead>
<tr style="background-color:#F0FFFF;">
<th><span>Company Name</span></th>
<th><span>Terms</span></th>
</tr>
</thead>
<tbody>';
$mpdf->WriteHTML($html);
if (mysqli_num_rows($item) > 0) {

while($row = mysqli_fetch_assoc($item)) {
$m++;

$html = '
<tr>
<td>'.$row['COMPANYNAME'].'</td>
<td>'.$row['terms'].'</td>
</tr>

<tr>
<td></td>
<td colspan="7">
<div id="demo'.$m.'" class="accordian-body collapse">
<table class="no-spacing">
<tr>
</tr>
';

$mpdf->WriteHTML($html);

$sql_1="SELECT * FROM `ar_iv` Inner Join `sl_iv` On ar_iv.DOCNO = sl_iv.DOCNO WHERE sl_iv.COMPANYNAME ='".$row['COMPANYNAME']."'";
$query_1 = mysqli_query($conn_connection, $sql_1);

while($DetRow = mysqli_fetch_assoc($query_1)) {
$html = '
<tr data-toggle="collapse" data-target="#demo'.$m.'" class="accordion-toggle">
<td>'.$DetRow['DOCNO'].'</td>
<td>'.$DetRow['DOCAMT'].'</td>
</tr>';
$mpdf->WriteHTML($html);
}

$html = '
</table>

</div>
</td>
</tr>
<br>';



$mpdf->WriteHTML($html);
}
} else {
echo "0 results";
}
$html = '
</tbody>
</table>';
$mpdf->WriteHTML($html);

$filename = $search.".pdf";
$mpdf->Output($filename,I);

exit;
?>

最佳答案

这是我的最新更新。它可以工作,但不确定它是否正确。

index.php

            <script>
function getCOMPANY() {
var form = document.frmSearch;
var dataString = $(form).serialize();
$.ajax({
type: "POST",
url: "ajax_aging.php",
data: dataString,
success: function(data){
$("#company-list").html(data);
}
});
return false;
}
</script>

ajax.php

        <?php
if(isset($_POST)) {
$COMPANYNAME = ($_POST);

$COMPANYNAME = $_POST['COMPANYNAME'];
$COMPANYNAME = is_array($COMPANYNAME) ? $COMPANYNAME : [$COMPANYNAME];

$companiesParam = '\''. join("', '", $COMPANYNAME) . '\'';
$fetch = "SELECT * 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 COMPANYNAME IN (".$companiesParam.") GROUP BY COMPANYNAME";
$results = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");

}

然后我在 ajax.php 处遇到了显示报告按钮的另一个问题。它说/reports/report.php?COMPANYNAME=Array&terms=

            <a href="report.php?COMPANYNAME=<?php echo $companiesParam; ?>&terms=<?php echo $terms; ?>" target="_blank">
<button style="margin-right:16px; float: right;" type="button" class="btn btn-secondary btn-sm">
<span class="glyphicon glyphicon-print"></span> PRINT Detail
</button>
</a>

报告.php

            <?php
require_once('../include/mysqlconnection.php');
include("../include/mpdf/mpdf.php");
$m=0;

$COMPANYNAME = $_GET["COMPANYNAME"];
$terms = $_GET['terms'];

$item_q = "SELECT * From `sl_iv`";
if($COMPANYNAME!=""){

$item_q.= " WHERE COMPANYNAME = '".$COMPANYNAME."'";
}
if($terms != "")
{
$item_q.= " WHERE terms = '".$terms."'";
}
else{
$item_q.= " GROUP BY COMPANYNAME ";
}

$item = mysqli_query($conn_connection, $item_q);
//$mpdf=new mPDF('c','A4','','',32,25,47,47,10,10);

$mpdf = new mPDF(
'', // mode - default ''
'A4', // format - A4, for example, default ''
'', // font size - default 0

$stylesheet = file_get_contents('mpdf.css');
$mpdf->WriteHTML($stylesheet,1);

$header = '
<table>

</table>
';

$footer = '
';

$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);

$html = '
<style>
.gradient {
background-color: #F0FFFF;
}
</style>

<p align="center" style="font color: #191970; font-size:20px"><b>Customer</b></p>


<table width="100%" class="no-spacing" style=" vertical-align: middle; font color: #191970; font-family: serif; font-size: 9pt;">
<thead>
<tr style="background-color:#F0FFFF;">
<th><span>Company Name</span></th>
<th><span>Terms</span></th>
</tr>
</thead>
<tbody>';
$mpdf->WriteHTML($html);
if (mysqli_num_rows($item) > 0) {

while($row = mysqli_fetch_assoc($item)) {
$m++;

$html = '
<tr>
<td>'.$row['COMPANYNAME'].'</td>
<td>'.$row['terms'].'</td>
</tr>

<tr>
<td></td>
<td colspan="7">
<div id="demo'.$m.'" class="accordian-body collapse">
<table class="no-spacing">
<tr>
</tr>
';

$mpdf->WriteHTML($html);

$sql_1="SELECT * FROM `ar_iv` Inner Join `sl_iv` On ar_iv.DOCNO = sl_iv.DOCNO WHERE sl_iv.COMPANYNAME ='".$row['COMPANYNAME']."'";
$query_1 = mysqli_query($conn_connection, $sql_1);

while($DetRow = mysqli_fetch_assoc($query_1)) {
$html = '
<tr data-toggle="collapse" data-target="#demo'.$m.'" class="accordion-toggle">
<td>'.$DetRow['DOCNO'].'</td>
<td>'.$DetRow['DOCAMT'].'</td>
</tr>';
$mpdf->WriteHTML($html);
}

$html = '
</table>

</div>
</td>
</tr>
<br>';



$mpdf->WriteHTML($html);
}
} else {
echo "0 results";
}
$html = '
</tbody>
</table>';
$mpdf->WriteHTML($html);

$filename = $search.".pdf";
$mpdf->Output($filename,I);

exit;
?>

关于javascript - 多选复选框ajax表过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40879702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com