Ich habe eine PHP und MySQL-Datenbank Name daily_data2 wo ich Tabelle im Datumsbereich mit Datum Zeitpicker (1. Abfrage) filtern kann, und ich kann auch filtern nach Abt (2. Abfrage), diese zwei Filteroption sind Arbeiten in verschiedenen Schaltflächen, aber mein Problem ist, wie kann das Ergebnis in der 1. Abfrage verwendet werden, um pro Abteilung (2. Abfrage) zu filtern? Oder sollte ich meine 2 Abfragen nur in 1 Bedingung kombinieren? kann mir jemand helfen. Unten ist mein Code.Filter wieder Ergebnis in PHP
<?php
$post_at = "";
$post_at_to_date = "";
if(isset($_POST['post_at']) && isset($_POST['post_at_to_date']))
{
$post_at = $_POST['post_at'];
$post_at_to_date = $_POST['post_at_to_date'];
$query = "SELECT * FROM daily_data2 WHERE Checkdate between '" . $post_at . "' and '" . $post_at_to_date . "'";
$search_result = filter($query);
}
else {
$sql = "SELECT * FROM daily_data2";
$search_result = filter($sql);
}
function filter($query)
{
$connect = mysqli_connect("localhost", "root", "","bio_db");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<?php
if(isset($_POST['go']))
{
$cmbDept = $_POST['cmbDept'];
$query ="SELECT * FROM $row array WHERE Campaign LIKE '".$cmbDept."' ";
$search_result = filterTable($query);
}
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "","bio_db");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<html>
<head>
<title>Employee Logs</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<style>
.table-content{border-top:#CCCCCC 4px solid; width:50%;}
.table-content th {padding:5px 20px; background: #F0F0F0;vertical-align:top;}
.table-content td {padding:5px 20px; border-bottom: #F0F0F0 1px solid;vertical-align:top;}
</style>
</head>
<body>
<h2 align="center">Time and Attendance Monitoring</h2>
<center>
<form name="frmSearch" method="POST" action="index.php">
<p class="search_input">
<input type="text" placeholder="From Date" id="post_at" name="post_at" value="<?php echo $post_at; ?>" class="input-control" />
<input type="text" placeholder="To Date" id="post_at_to_date" name="post_at_to_date" style="margin-left:10px" value="<?php echo $post_at_to_date; ?>" class="input-control" />
<input type="submit" name="search" value="Search" >
</p>
<form method="POST" action="excel.php">
<input type="hidden" name="cmbDept" value="<?php echo isset($_POST['cmbDept']) ? $_POST['cmbDept'] : ''; ?>">
<input type="submit" name="export_excel" class="btn btn-success" value="Export to Excel">
</form>
<form action="index.php" method="post">
<select id="cmbDept" name="cmbDept">
<option value = '' selected="selected">Filter by Department</option>
<option value = 'TKV'>TKV</option>
<option value = 'NA'>NA</option>
<option value = 'PURE-INC'>PURE INC</option>
<option value = 'DUTY-FREE'>DUTY-FREE</option>
<option value = 'HQL'>HQL</option>
<option value = 'PRO-XPN'>PRO-XPN</option>
<option value = 'Mate1'>Mate1</option>
<option value = 'STUDENT-rUS'>STUDENT-rUS</option>
<option value = 'COLLECTIONS'>COLLECTIONS</option>
<option value = 'NTD'>NTD</option>
<option value = 'DATA RESEARCHER'>DATA RESEARCHER</option>
<option value = 'VA'>DATA RESEARCHER</option>
</select>
<input type="submit" name="go" value="Filter"><br><br>
</center>
<table align="center" width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Userid</th>
<th>Name</th>
<th>Campaign</th>
<th>Checkdate</th>
<th>Hoursworked</th>
<th>Overtime</th>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td style="text-align:center;"><?php echo $row['Userid'];?></td>
<td width="200"><?php echo $row['Name'];?></td>
<td style="text-align:center;"><?php echo $row['Campaign'];?> </td>
<td width="100" style="text-align:center;"><?php echo $row['Checkdate'];?></td>
<td style="text-align:center;"><?php echo $row['Hoursworked'];?></td>
<td style="text-align:center;"><?php echo $row['Overtime'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$.datepicker.setDefaults({
showOn: "button",
buttonImage: "datepicker.png",
buttonText: "Date Picker",
buttonImageOnly: true,
dateFormat: 'yy-mm-dd'
});
$(function() {
$("#post_at").datepicker();
$("#post_at_to_date").datepicker();
});
</script>
</body>
</html>
Sie möchten eine weitere Where-Klausel in der gleichen Abfrage hinzufügen, so dass Sie nur einmal Ihre Datenbank abfragen müssen. HINWEIS: Sie sollten eine Form von vorbereiteten Abfragen verwenden, wenn Sie mysql in PHP verwenden. –