///////////////FILLING ARRAY WITH DUMMY DATA//////////////////// $key = array(); for($i=0; $i<200; $i++) { //fill array data $key[] = "num = ".$i; } //////////////////////////////////////////////////////////////// /////////////////////START OF ARRAY PAGINATION CODE///////////////////// $ptemp="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $pt=explode('&',$ptemp); if (strpos($ptemp,'pageno')) array_pop($pt); $pt=implode('&',$pt); $ptemp=$pt; $array=$key; // REPLACE $KEY WITH YOUR ARRAY VARIABLE $page = $_REQUEST['pageno']; $currentpage = isset($page) ? (integer)$page : 1; $numperpage = 10; //NUMBER OF RECORDS TO BE DISPLAYED PER PAGE $total = count($array); $numofpages = ceil($total / $numperpage); //TOTAL NUMBER OF PAGES if(isset($array)) { if (($currentpage > 0) && ($currentpages <= $numofpages)) { //STARTING LOOP FOR ARRAY DATA $start = ($currentpage-1) * $numperpage; for($i=$start;$i<=($numperpage+$start-1);$i++) { ///////////PLACE YOUR CODE HERE////////////////////////// echo $array[$i] .' '; //////////////////////////////////////////////////////// } } } if ($currentpage != 1) { //GOING BACK FROM PAGE 1 SHOULD NOT BET ALLOWED $previous_page = $currentpage - 1; $previous = ' < '; } $pages = ''; for ($a=1; $a<=$numofpages; $a++) { if ($a == $currentpage) $pages .= $a .' '; else $pages .= ''. $a .' '; } $pages = substr($pages,0,-1); //REMOVING THE LAST COMMA (,) if ($currentpage != $numofpages) { //GOING AHEAD OF LAST PAGE SHOULD NOT BE ALLOWED $next_page = $currentpage + 1; $next = ' >'; } echo ' '. $previous . $pages . $next; //PAGINATION LINKS /////////////////////END OF ARRAY PAGINATION CODE/////////////////////
Do feel free to ask any questions that you may have concerns to web. No Compromise on Learning!
Saturday, March 29, 2014
Php Array Pagination Script
Monday, March 24, 2014
How to calculate difference in days between two dates in MySQL
Let's say we have a MySQL table where one column (date or datetime type) is namedactivated and contains dates in one of the YYYY-MM-DD or YYYY-MM-DD HH:MM:SSformats from the past and we need to calculate the difference in days since that date untill current date for each row.
First let's see a preview of the activated column:
First let's see a preview of the activated column:
mysql> SELECT activated FROM table_dates LIMIT 0,5;
+--------------+ | activated | +--------------+ | 2007-06-06 | | 2007-10-15 | | 2007-10-17 | | 2007-10-18 | | 2007-10-19 | +--------------+ 5 rows in set (0.00 sec) mysql> |
so we see dates lik 06th of June, 15th of October and so on. Now, let's calculate the difference between these dates and current date:
mysql> SELECT DATEDIFF(CURDATE(), activated) AS intval FROM table_dates LIMIT 0,5; +--------+ | intval | +--------+ | 259 | | 128 | | 126 | | 125 | | 124 | +--------+ 5 rows in set (0.00 sec) |
so the difference in days between 6th of June and present day is 259 days. Same with the others.
I used in the queries above two MySQL date functions: DATEDIFF() and CURDATE().
Also take a good look at MySQL Date and Time Functions and MySQL The DATETIME, DATE, and TIMESTAMP Column Types.
Subscribe to:
Posts (Atom)
How to backup and download Database using PHP
< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...
-
Welcome to the next part of OpenLayers 3 for Beginners! If you have not worked through parts one or two yet, you can hop over to them he...
-
What is PHPSpreadSheet Library PHPSpreadSheet library is purely writter in PHP and it main purpose of communicate your PHP application with ...
-
Welcome to OpenLayers 3 for Beginners: Part 2. If you have not been to and completed OpenLayers 3 Part 1 yet, head over to http://chris...