Skip to main content

Posts

Showing posts from June, 2010

Find next month and Year from today

This script prints out the dates of 1 month and 1 year ahead of today's date. php code: <?php echo 'Next month: '; echo date('Y',strtotime('+1 month')).'-'.date('m',strtotime('+1 month')).'-'.date('d',strtotime('+1 month')); echo '<br>'; echo 'Next year: '; $y = date("Y-m-d",strtotime("+1 years")); echo $y; ?>

Find Last day of a month

Here is a small function that returns the last day of a month of an year, both passed to it in the numerical form. <?php function getlastdayofmonth($month, $year) { for ($day = 28; $day < 33; $day++) { if (!checkdate($month, $day, $year)) return $day-1; } } $l=getlastdayofmonth(2,2008); echo 'Last day of Feb 2008: '.$l.'<br>'; $m=getlastdayofmonth(6,2010); echo 'Last day of Jun 2010: '.$m.'<br>'; $n=getlastdayofmonth(12,2010); echo 'Last day of Dec 2010: '.$n.'<br>'; ?> Output: Last day of Feb 2008: 29 Last day of Jun 2010: 30 Last day of Dec 2010: 31

Identify the user's browser

Sometimes there arises a need to identify the user's browser. It is pretty easy to find browser with jquery. So if you have included jquery in your page, it takes a simple line to identify the browser:  if ($. browser . msie ) {} // IE if (($.browser.msie) && ($.browser.version == '6.0')) {} // IE6 if ($. browser . opera ) {} // opera if ($. browser . mozilla) {} // Firefox With the help of php, you can get the browser  details with the help of:  $_SERVER['HTTP_USER_AGENT']; Or you can even use the combined version of php and javascript. php + javascript code: <script type="text/javascript"> var string1 = "<?php echo $_SERVER['HTTP_USER_AGENT']; ?>"; // Browser string var myRegExp1 = /Firefox/; var matchPos1 = string1.search(myRegExp1); var myRegExp2 = /Chrome/; var matchPos2 = string1.search(myRegExp2); var myRegExp3 = /MSIE/; var matchPos3 = string1.search(myRegExp3); if(matchPos1 != -1)

Ajax pagination

Have you ever tried the pagiantion with php using Ajax ? We just pass the query, starting page and records per page you want to display in the pagination. Lets start with a simple example to understand how it can be done. steps: 1: create a database 'ajax' 2: create a table 'students': CREATE TABLE IF NOT EXISTS `students` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) 3. insert data into the table: INSERT INTO `students` (`id`, `name`) VALUES (1, 'Reneesh'),(2, 'Aniesh'),(3, 'Babu'),(4, 'Antony'),(5, 'Praveesh'), (6, 'Dixon'),(7, 'Sanju'),(8, 'Neeraj'),(9, 'Siju'),(10, 'Noble'), (11, 'Bibin'),(12, 'Febin'),(13, 'Binu'),(14, 'Charles'),(15, 'jaggu'), (16, 'mani'),(17, 'milu'),(18, 'aravind'),(19, 'jay'),(20, 'hari'); 4. Change the mysql connecti