2
的index.phpCSV文件輸出基地
我想導出基於選定本月
<div id="page-wrapper">
<div class="container-fluid">
<h2 class="form-signin-heading">Schedule Management</h2><hr />
<button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span> Add Schedule</button>
<button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span> View Schedule</button>
<hr />
<div class="content-loader">
<form method="post" action="index.php">
Select a month <select name="months" onchange ='this.form.submit()'>
<option value="0"> </option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Sched #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Check In Date</th>
<th>Check Out Date</th>
<th>Room Rate</th>
<th>Reservation Fee</th>
<th>Date Paid</th>
<th>Mode of Paymnet</th>
<th>Status</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
if(isset($_POST['months'])){ $months = $_POST['months']; }else { $months='';}
$stmt = $db_con->prepare("SELECT * FROM tblguest WHERE MONTH(checkin) = '".$months."' ");
//this is my solution to filter my table data base on the selected months in the index.php table
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['lname']; ?></td>
<td><?php echo $row['checkin']; ?></td>
<td><?php echo $row['checkout']; ?></td>
<td><?php echo $row['rrate']; ?></td>
<td><?php echo $row['reservefee']; ?></td>
<td><?php echo $row['datepaid']; ?></td>
<td><?php echo $row['modepayment']; ?></td>
<td><?php echo $row['stats']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<a class="btn" href="export.php">Export</a>
</div>
</div>
<br />
<div class="container">
</div>
export.php
出口按鈕工作的數據,但我想過濾我的數據就像在我的表中index.php基於選擇的月份......但現在我只能執行時,我點擊導出按鈕我的數據庫上的整個數據獲取輸出到.csv
<?php
require_once 'dbconfig.php';
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=exported-data.csv');
$stmt = $db_con->prepare("SELECT * FROM tblguest ");
$stmt->execute();
$filename = date('d.m.Y').'.csv';
$data = fopen($filename, 'w');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$csv = implode(',', $row) . "\n";
fwrite($data, $csv);
print_r($csv);
}
echo "\r\n";
fclose($data);
?>
在選擇任何選項時將參數添加到URL。通過這種方式,您可以根據城市進行鏈接,並且可以使用$ _GET參數或您的應用程序方式獲取參數。 –
請大家看看,我寫了答案,如果你覺得很好,那麼你可以把它標記爲已接受並且投票贊成。 –