【发布时间】:2018-03-09 09:00:06
【问题描述】:
我这几天一直在看/阅读教程、编码/重新编码等,但仍然无法让我的功能正常工作。我有一个由使用 PHP 的 mySQL 数据库中的数据填充的 HTML 表组成的网页。我已经添加了一个日期选择器、脚本和一个带有用户输入的表单,但是没有成功让 HTML 表根据那些 from 和 to 日期从日期选择器。我的困难在于 PDO 语法:我找不到任何使用 PDO 的教程。有人可以帮忙吗?我已经尝试过 AJAX 和 jquery 数据表,但它们最终破坏了我的表,我仍然无法让日期选择器返回结果。图片如下所示,是我的页面的样子。
screenshot of page with styling
<!-- This is my form -->
<form name="frmSearch" method="post" action="">
<p class="search_input">
<input type="text" placeholder="From Date" id="from_date" name="from_date" class="input-control" />
<input type="text" placeholder="To Date" id="to_date" name="to_date" style="margin-left:10px" class="input-control" />
<input type="submit" name="go" value="Search" >
</p>
</form>
<!-- This is my table including <thead>, <tbody> markup and php for populating the table from the database -->
<table class="user-table">
<thead>
<th><a href="admin_view_general_ledger.php?sort=id">ID</a></th>
<th><a href="admin_view_general_ledger.php?sort=date">Date</th>
<th>Receipt #</th>
<th><a href="admin_view_general_ledger.php?sort=mem_no">Mbr #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Description</th>
<th>Transaction Type</th>
<th>(-/+) Amount</th>
<th>Expense Type</th>
<th>Income type</th>
<th>Balance</th>
<th>Added By</th>
<th>Action</th>
</thead>
<tbody>
<?php
include 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM general_ledger a
LEFT JOIN balance b ON a.gen_led_id=b.bal_gen_led_id
LEFT JOIN receipts c ON a.gen_led_id=c.rec_gen_led_id
LEFT JOIN ref_gen_led_expense_type d ON
a.gen_led_expense_type=d.ref_gen_led_expense_typ
LEFT JOIN ref_gen_led_transaction_type e ON
a.gen_led_transaction_type=e.ref_gen_led_transaction_typ
LEFT JOIN ref_gen_led_income_type f ON
a.gen_led_income_type=f.ref_gen_led_income_typ
LEFT JOIN member g ON a.gen_led_users_mem_no=g.mem_no
LEFT JOIN balance h ON a.gen_led_id=h.bal_gen_led_id
LEFT JOIN users i ON a.gen_led_add_by=i.user_mem_no';
<!-- This is some code I have to sort the table by column name with a page refresh -->
if(isset($_GET['sort'])){
if ($_GET['sort'] == 'id')
{
$sql .= " ORDER BY gen_led_id DESC";
}
elseif ($_GET['sort'] == 'date')
{
$sql .= " ORDER BY gen_led_trans_date";
}
elseif ($_GET['sort'] == 'mem_no')
{
$sql .= " ORDER BY mem_no";
}
}
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['gen_led_id'] . '</td>';
echo '<td>'. $row['gen_led_trans_date'] . '</td>';
echo '<td>'. $row['rec_receipt_no'] . '</td>';
echo '<td>'. $row['mem_no'] . '</td>';
echo '<td>'. $row['mem_fname'] . '</td>';
echo '<td>'. $row['mem_lname'] . '</td>';
echo '<td>'. $row['gen_led_description'] . '</td>';
echo '<td>'. $row['ref_gen_led_transaction_desc'] . '</td>';
echo '<td>'. $row['gen_led_amount'] . '</td>';
echo '<td>'. $row['ref_gen_led_expense_desc'] . '</td>';
echo '<td>'. $row['ref_gen_led_income_desc'] . '</td>';
echo '<td>'. $row['bal_acct_balance'] . '</td>';
echo '<td>'. $row['gen_led_add_by'] . '</td>';
echo '<td><a class="btn" href="admin_user_receipt.php?rec_receipt_no='.$row['rec_receipt_no'].'">View Receipt</a></td>';
echo ' ';
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
<!-- This is my script which does display the datepicker when the input boxes are clicked -->
<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() {
$("#from_date").datepicker();
$("#to_date").datepicker();
});
</script>
【问题讨论】:
-
欢迎来到 SO。请访问stackoverflow.com/tour
标签: php html pdo jquery-ui-datepicker