【发布时间】:2014-09-15 03:43:54
【问题描述】:
我正在使用数据表编辑器来填充网格并希望使用不同的“WHERE”子句对其进行过滤。我的代码如下:
jQuery
// Valid Customer Accounts
$('#lnkValidCustomers').click(function () {
// Redraw Grid
customersTable.ajax.url('dataGridQuery.php?varCurrentCustomers=y&varInvalidCustomers=n').load();
});
// Invalid Customer Accounts
$('#lnkInvalidCustomers').click(function () {
// Redraw Grid
customersTable.ajax.url('dataGridQuery.php?varCurrentCustomers=n&varInvalidCustomers=y').load();
});
//All Customer Accounts
$('#lnkShowAllCustomers').click(function () {
// Redraw Grid
customersTable.ajax.url('dataGridQuery.php?varCurrentCustomers=y&varInvalidCustomers=y').load();
});
PHP
// Database Fields
$editor = Editor::inst( $db, 'tblCustomers', 'customerID' )
->fields(
Field::inst( 'customerID' ),
Field::inst( 'customerName' ),
Field::inst( 'customerNotValidDate' )
);
// Where Clauses
if (isset($_GET['varCurrentCustomers']) && $_GET['varCurrentCustomers']=='y' && isset($_GET['varInvalidCustomers']) && $_GET['varInvalidCustomers']=='n') { // All Valid Customers.
// Apply Filter
$editor
->where('tblCustomers.customerNotValidDate', '', '=' );
} else if (isset($_GET['varCurrentCustomers']) && $_GET['varCurrentCustomers']=='n' && isset($_GET['varInvalidCustomers']) && $_GET['varInvalidCustomers']=='y') { // All Invalid Customers.
// Apply Filter
$editor
->where( 'tblCustomers.customerNotValidDate', '', '!=' );
} else if (isset($_GET['varCurrentCustomers']) && $_GET['varCurrentCustomers']=='y' && isset($_GET['varInvalidCustomers']) && $_GET['varInvalidCustomers']=='y') { // All Customers.
// Apply Filter
// No Filter
}
// Process Json
$editor
->process( $_POST )
->json();
我遇到的问题是 $_GET 变量重复,因此没有应用所需的 WHERE 子句。下面是参数结果的控制台示例:
控制台
gridNumber 3
varCurrentCustomers y
varCurrentCustomers n
varInvalidCustomers y
varInvalidCustomers n
我认为问题在于尝试将 PHP $_GET 参数用作 jQuery 变量;请告诉我。感谢您在这方面的任何帮助。我是一名自学成才的业余 Web 开发人员。 :)
【问题讨论】:
标签: javascript php jquery ajax datatables