以前我正在使用Multiple select复选框来显示表记录,可以在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 </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>
report.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;
?>
答案 0 :(得分:0)
这是我最新的更新。它工作但不确定它是否正确。
<强>的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>
<强> report.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;
?>