Show the number of displayed results

we use the code below to filter strings based on selected from and to date.

we can successfully filter and display the 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 )); } 

the form

 <form name="frmSearch" method="post" action=""> <input type="text" placeholder="From Date" id="post_at" value="<?php if ($orderFromDate != '') { $newPostStartDate = date('Ym-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('Ym-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(); }); 

enter image description here

now we want to display how many rows are selected. if the result is similar to the previous image, we want to display "rows: 1". I am very new to php and I tried under the code but didn't display anything:

 $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); } 

change

now we want to display the number of rows displayed. , so we tried to make the code below. its display as shown below. its display is "rows = 3" . because it considers the column "entity_id" of the table "sales_flat_order" . but I want "rows: 9" since you can see 9 rows in the image.

enter image description here

enter image description here

 require_once '../../app/Mage.php'; Mage::app(); // specify the date picker date-format $format = 'Ym-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('Ymd H:i:s'), 'todate' => $dateTo->format('Ymd 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"; } 

full code: http://pastebin.com/hMUEusvb

+7
javascript jquery php datepicker magento
source share
4 answers

You can count the number of rows with js. Add the following code at the end of your code. Replace selector1 with the class name, which is used only for strings. Examine your page in the browser and find a class that is present only in lines and is used once in a row. Then replace selector2 with the class or id where you want to display the 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 this through PHP. Paste the code in which it displays the search result. Your current code does not work, because your code sends a response on line 293 of the http://pastebin.com/QKMj0k2p file. You can find this on the tab in the browser network and see how to send the request, where it sends the request, and what comes in the answer is from there. If you can find where the response is sending, it will be easy to find out what code represents the rendering lines. This will help you solve your problem.

0
source share

You can count the selected id from your mysqli query. Try this in mysqli query

  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 } 
+2
source share

I think you have a mistake that is not in your question. If you want to fix this problem. You can use javascript. You only need 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); } ); 
+1
source share

your php code should look like this

 // if posted data are not empty if(!empty($_POST['post_at']) && !empty($_POST['post_at_to_date'])) { // specify the date picker date-format $format = 'Ym-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('Ymd H:i:s'), 'todate' => $dateTo->format('Ymd 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"; } 
0
source share

All Articles