我们使用以下代码根据所选的From& amp;来过滤行。到目前为止。
我们能够成功过滤&显示结果。
PHP
/* to show selected date */
if (isset($_POST['post_at']) && $_POST['post_at'] != '')
{
$orderFromDate = $_POST['post_at'] . " 00:00:00 ";
}
else
{
$orderFromDate = '';
}
if (isset($_POST['post_at_to_date']) && $_POST['post_at_to_date'] != '')
{
$orderToDate = $_POST['post_at_to_date'] . " 23:59:59 ";
}
else
{
$orderToDate = '';
}
/* to show selected date end*/
function getDesignerCollection()
{
/* date search */
if (isset($_POST['post_at']) && $_POST['post_at'] != '')
{
$orderFromDate = $_POST['post_at'] . " 00:00:00 ";
}
else
{
$orderFromDate = '';
}
if (isset($_POST['post_at_to_date']) && $_POST['post_at_to_date'] != '')
{
$orderToDate = $_POST['post_at_to_date'] . " 23:59:59 ";
}
else
{
$orderToDate = '';
}
/* date search end*/
$accountType = $rows['type'];
if ($accountType == "admin")
{
if ($orderFromDate != '') $order->addFieldToFilter('created_at', array(
'gteq' => $orderFromDate
));
if ($orderToDate != '') $order->addFieldToFilter('created_at', array(
'lteq' => $orderToDate
));
}
形式
<form name="frmSearch" method="post" action="">
<input type="text" placeholder="From Date" id="post_at"
value="<?php
if ($orderFromDate != '')
{
$newPostStartDate = date('Y-m-d', strtotime($_POST['post_at']));
echo $newPostStartDate;
} ?>" name="post_at" />
<input type="text" placeholder="To Date" id="post_at_to_date"
value="<?php
if ($orderToDate != '')
{
$newPostEndDate = date('Y-m-d', strtotime($_POST['post_at_to_date']));
echo $newPostEndDate;
} ?>"name="post_at_to_date" />
<input type="submit" name="search" value="search" id="searchButton">
<input type="button" value="Reset" id="clear-dates">
</form>
jquery的
jQuery.datepicker.setDefaults({
showOn: "button",
buttonImage: "assets/img/datepicker.png",
buttonText: "Date Picker",
buttonImageOnly: true,
dateFormat: 'yy-mm-dd'
});
$(function() {
$("#post_at").datepicker();
$("#post_at_to_date").datepicker();
});
现在我们要显示选择了多少行。如果结果如上图所示我们要显示“rows:1”。我是非常新的php&amp;我试过下面的代码,但它没有显示任何内容:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = mysqli_query($link, "SELECT entity_id , created_at FROM sales_flat_order ORDER BY Name")) {
/* determine number of rows result set */
$row_cnt = mysqli_num_rows($result);
printf("Result set has %d rows.\n", $row_cnt);
/* close result set */
mysqli_free_result($result);
}
修改
现在我们要显示显示的行数。所以我们尝试了以下代码。它显示如下图像。它显示“rows = 3”。因为它考虑了“sales_flat_order”表的“entity_id”列。但是我想要“行:9”,因为你可以在图像中看到9行。
require_once '../../app/Mage.php';
Mage::app();
// specify the date picker date-format
$format = 'Y-m-d';
// if posted data are not empty
if(!empty($_POST['post_at']) && !empty($_POST['post_at_to_date']))
{
if (!empty($_POST['post_at'])) {
$dateFrom = DateTime::createFromFormat($format, $_POST['post_at']);
}
if (!empty($_POST['post_at_to_date'])) {
$dateTo = DateTime::createFromFormat($format, $_POST['post_at_to_date']);
}
// Get the resource model
$resource = Mage::getSingleton('core/resource');
// Retrieve the read connection
$read = $resource->getConnection('core_read');
// MySQL query
$query = 'SELECT entity_id, created_at, dproduct_id FROM sales_flat_order WHERE created_at BETWEEN :fromdate AND :todate ;';
// Bind MySQL parameters
$binds = array(
'fromdate' => $dateFrom->format('Y-m-d H:i:s'),
'todate' => $dateTo->format('Y-m-d H:i:s')
);
// Execute the query and store the results in $results
$results = $read->fetchAll($query,$binds);
echo "rows : ".count($results);
echo "<br>";
print_r($results);
}
else {
echo "error you have not specified any dates";
}
答案 0 :(得分:2)
您可以从mysqli查询itsel中计算所选的ID。在mysqli查询中尝试此操作
if ($result = mysqli_query($link, "SELECT count(entity_id) as Total_count,entity_id , created_at FROM sales_flat_order ORDER BY Name")) {
// Your process
}
答案 1 :(得分:1)
我认为您的错误在您的问题中不存在。如果您只想解决此问题。你可以使用JavaScript。您只需要知道确切的选择器。
$(document).ready( function (){
//your selector would direct li or td if there is no other li td then it works other wise you have select parent then li or td like below comment
//$(".class li").length
var count = $("li").length;
$("yourCounter").html(count);
} );
答案 2 :(得分:0)
你的 PHP 代码应该是这样的
// if posted data are not empty
if(!empty($_POST['post_at']) && !empty($_POST['post_at_to_date'])) {
// specify the date picker date-format
$format = 'Y-m-d';
// create dates
$dateFrom = DateTime::createFromFormat($format, $_POST['post_at']);
$dateTo = DateTime::createFromFormat($format, $_POST['post_at_to_date']);
// if equal dates are applied to form
if($_POST['post_at']==$_POST['post_at_to_date']) {
$dateTo->add(new DateInterval('T23H59M59S'));
}
// Get the resource model
$resource = Mage::getSingleton('core/resource');
// Retrieve the read connection
$read = $resource->getConnection('core_read');
// MySQL query
$query = 'SELECT `entity_id`, `created_at` FROM `sales_flat_order` WHERE `created_at` BETWEEN :fromdate AND :todate ;';
// Bind MySQL parameters
$binds = array(
'fromdate' => $dateFrom->format('Y-m-d H:i:s'),
'todate' => $dateTo->format('Y-m-d H:i:s')
);
// Execute the query and store the results in $results
$results = $read->fetchAll($query,$binds);
echo "Orders count: ".count($results);
} else {
echo "error you have not specified any dates";
}
答案 3 :(得分:0)
您可以使用js计算行数。在代码末尾添加以下代码。将selector1替换为仅用于行的类名。在浏览器中检查您的页面,找到一个只存在于行中并且一次连续使用一次的类。 然后将selector2替换为要显示行数的类或id。
<script>
$(document).ready(function () {
var count = 0;
//use class unique in each row.
$("selector1").each(function () {
count++;
});
//use class or id where you want to display count
$("selector2").prepend("Number of rows "+count);
});
如果你想通过PHP完成它。请将代码粘贴到呈现搜索结果的位置。 您当前的代码无效,因为您的代码在文件http://pastebin.com/QKMj0k2p的第293行发回了响应 您可以在浏览器的网络选项卡中找到它,并在搜索提交中查看它发送请求的位置以及从那里响应的内容。如果您可以找到它发送响应的位置,则很容易知道哪些代码正在呈现行。解决您的问题将更有帮助。