Show the count of Displayed results
we are using below code to filter rows based on selected From & To date.
we can able to filter successfully & displaying results.
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
<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();
});
now we want to display how many rows are selected. if result is as above image we want to display "rows : 1". i am very new to php & i tried below code , but its not displaying anything:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", 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);
}
edit
now we want to display count of how many rows are displayed. so we tried below code. its displaying like below image. its displaying "rows = 3" . because its considering "entity_id" column of "sales_flat_order" table. but i want "rows : 9" as you can see 9 rows in image.
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";
}
complete code : http://pastebin.com/hMUEusvb
You can count number of rows by using js. Add following code at the end of your code. Replace selector1 with class name which is used only for rows. Inspect your page in browser and find a class which is present only in rows and used once at a time in a row. Then replace selector2 with class or id where you want to display number of rows.
<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);
});
If you want to handle it done through PHP. Please paste the code where it renders the search result. Your current code is not working because your code send response back on line 293 of file http://pastebin.com/QKMj0k2p You can find that in network tab of browser and see on search submit where it send request and what comes in response from there. If you can find where it is sending response back it will be easy to know which code is rendering rows. It will be more help full to solve your problem.
您可以从您的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
}
I think you have an error which is not present in your question. If you only want to fix this Issue. You can use JavaScript. You only have to know the exact selector.
$(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);
} );
链接地址: http://www.djcxy.com/p/37602.html
上一篇: Bootstrap或Material Design Lite或两者
下一篇: 显示显示结果的数量