Thursday, 17 September 2015

12 Reasons to Choose PHP for Developing Website

The Internet industry has been revolutionizing numerous technologies for the betterment. Most web developers choose PHP to design their own website. The main reason is it is an open-source server-side scripting language that provides multifarious features. 
 
It is also an interpreted script language best suited for developing websites as per your preferences. Further, PHP is highly beneficial for its users since it is compatible with both Windows and Unix-based operating systems. It also enables the users to easily manage and upgrade their PHP based websites without any burdens. 
 
If you are looking to create a website then choose PHP to build exceptional quality websites and web applications effortlessly. Execution of a wonderful websites can easily be achieved with the support of expert PHP developers who have vast experience in the online industry.

This blog is very useful for the users as it contains various information on why to choose PHP over other languages! Let’s have a look on the reasons why PHP is extensively used for website development. 

1. User – friendly 

 
PHP is absolutely simple to comprehend than other programming languages. Since it is an easy and powerful language, it has been widely used for creating web based applications that requires utmost functionality with minimal coding. In addition, PHP based web applications are extremely secure as compared to applications of various other programming languages.
  

2. Flexibility 

 
This is a one only language that provides maximum level of flexibility as compared to languages like Asp, .Net and etc. It is ideal for any users who look to extend the high-end programming language to exactly match the custom requirements of any businesses.
Moreover, it is open source software which allows the user to use any editor to write the code. It can also be combined with diverse libraries such as graphics and Extensible Markup language (XML) and etc. 
 

3. Dynamic


It is an effective language enables you to develop lively websites which refresh automatically. Using PHP for creating websites may not require any updates manually for refreshing it. PHP web development includes a various interesting process that mesmerizes the users.

4. Cost Effective


PHP is being widely used by an extensive range of users for the past 2 years as it is economic for developing a website efficiently. Besides, it can easily be obtained free of charge from the internet. The users can also download the latest version for free of cost at any time. It is highly beneficial for web developers who strive to make a new entry in the online market.  

5. Data Processing 

 
Developing any website using PHP supports the user to include fast data processing features. It also helps to improve the website functions to a greater extent.

6. Open Source


PHP is universally recognized open source language which provides ultimate solutions for all website development needs. The reason behind the success of this high end language is, it is totally free and simple to use.

7. High Performance 


PHP is a unique language that completely improves speed of development, rather increasing the speed of execution. It operates on a conventional web stack. PHP makes full use of Apache web server. Likewise, PHP applications utilize Apache web server as well as the MySQL database.

8. Cross Platform


Now, it is quite easy to create cross-platform applications with PHP since it works amazing on UNIX, LINUX and Windows platforms. It is developed in such a way that it interfaces with Apace and MYSQL. If you are interested to develop a cross platform application, PHP is the right choice.

9. Prominent in CMS


Any websites that has been developed from PHP are fully customized and assists the programmers to develop websites as per their clients’ preferences.

10. Embedding Qualities


One of the superior qualities of PHP language is that it can easily be embedded into HTML within a very few steps. This is an exemplary language supports web programmers to convert an existent static website into a whole new active one.

11. Extensions


Being a flexible and innovative language, it provides many numbers of extensions. The output of this language is fully significant and helps the users to determine their return on investment.

12. Instant


This is considered as a fast and instant language which caters quick turnaround time. By employing a well experienced PHP developer, you can obtain a prompt solution that you want to achieve for a very long time. 

These are some of the main reasons why all the web developers choose PHP over other languages for creating an unimaginable PHP web development projects.

Thursday, 13 August 2015

working with PHP and MYSQL dates

$dt=date('d/m/Y');                                                                // Gives Todays date  
            
$day = date('w');                              // Gives week day number  sun-sat is 0-6, sunday is zero
$sday = $day - 0;  // Last sunday
$eday = 7 - $day;  // Next sunday

$ws = date('d/m/Y', strtotime('-'.$sday.' days'));
$lastsunday = date('d/m/Y', strtotime('-'.$sday.' days'));

$we = date('d/m/Y', strtotime('+'.$eday.' days'));
$nextsunday  = date('d/m/Y', strtotime('+'.$eday.' days'));

$no_of_mand=16;

$chkrep = mysql_result(mysql_query("SELECT IFNULL(count(*),0) FROM meerepdone where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$ws','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$we','%d/%m/%Y')"),0);

if($chkrep==0) // The week records exists in DB or not
{

echo "<br/><br/><center><font color='darkblue'><h2>There are no Records in this week in DB</h2></font>
 </center>";
 echo "<br/><br/><center><font color='darkblue'><h2> FROM DATE : $ws - To date : $we</h2></font>
 </center>";
 exit(0);
 
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

/* $query="SELECT distinct tdate from meerep where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$ws','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$we','%d/%m/%Y')"; */

$initqry=mysql_result(mysql_query("SELECT IFNULL(count(*),0) FROM fortnight where 
        STR_TO_DATE(fromdt,'%d/%m/%Y')=STR_TO_DATE('$ws','%d/%m/%Y') and  
        STR_TO_DATE(todate,'%d/%m/%Y')=STR_TO_DATE('$we','%d/%m/%Y')"),0);

/* the above Query compares the php dates with mysql dates */


if($initqry==0){

$transqry = "SELECT DISTINCT mandal from meerep";
$res=mysql_query($transqry);
$nor=mysql_numrows($res);
$i=0;$mand='';
$iconn = new mysqli($servername, $username, $password, $database);
while($i<$nor){
$mand=mysql_result($res,$i,"mandal");
$insqry = "INSERT INTO fortnight(mandal,fromdt,todate) VALUES('$mand','$lastsunday','$nextsunday')";

$iconn->query($insqry);
  $i++;
}
$iconn->close();

$query = "SELECT DISTINCT mandal from meerep";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
$sl=1;$mand='';
$getpendper = 0;
$weekper = 0;
$iconn = new mysqli($servername, $username, $password, $database);
while($i<$num){

 $mand=mysql_result($result,$i,"mandal");
 $minper = mysql_result(mysql_query("SELECT IFNULL(MIN(pendper),0) FROM meerep where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$lastsunday','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$nextsunday','%d/%m/%Y') and  mand=trim('$mand')"),0);
 $maxper = mysql_result(mysql_query("SELECT IFNULL(MAX(pendper),0) FROM meerep where
        STR_TO_DATE(tdate,'%d/%m/%Y')>=STR_TO_DATE('$lastsunday','%d/%m/%Y') and
        STR_TO_DATE(tdate,'%d/%m/%Y')<=STR_TO_DATE('$nextsunday','%d/%m/%Y') and  mand=trim('$mand')"),0);

 $weekper = 100 - round(($minper/$maxper) * 100) ;   // calculating percentage

 $updqry = "UPDATE fortnight SET percen='$weekper' WHERE mandal='$mand' and fromdt='$lastsunday' and todate='$nextsunday'";

 $iconn->query($updqry);                          /* A simple Update through PHP */ 
 $i++; $sl++;
}                      // End of While loop

$iconn->close();

}            // End of If condition fortnight having zero records for the week dates

creating dynamic arrays and dynamic variables example in php

<?php

$test = array();                                           //  The Dynamic array declaration
$i=0;
$nl = array("abc","yzc","ijk");                  // Static array

for($i=0;$i<3;$i++){
echo $nl[$i]."\n";                                // Displaying static array
}

/* Gives out put as
abc
yzc
ijk


*/

for($i=0;$i<3;$i++){
$test[$nl[$i]]="number:".$i + 1;      
${"file" . $i} = "test $i";

}

var_dump($test);

/* Gives output as

array(3) { ["abc"]=> int(1) ["yzc"]=> int(1) ["ijk"]=> int(1) } 

*/


echo "<br/>".$test["yzc"];     // Output is one i.e., 1

for($i=0; $i<=2; $i++) {
echo "<br/>".${"file".$i};
}

/* Gives output as

test 0
test 1
test 2


*/

?>

Thursday, 30 July 2015

Adding and Subtracting Dates and Times in PHP

$today = date(‘d/m/Y’);  // Todays date in date/month/4 digit year format

$yesterdaydt=date(‘d/m/Y’,strtotime(“-1 days”));  // GET Yesterdays Date


Subtracting days from a date

The following example will subtract 3 days from 1998-08-14. The result will be 1998-08-11.

$date = "1998-08-14";                                    
$newdate = strtotime ( '-3 day' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                  
echo $newdate;                                           
 
Subtracting Weeks from a date

The following example will subtract 3 weeks from 1998-08-14. The result will be 1998-07-24. Notice that the only difference in the code is the week statement.

$date = "1998-08-14";                                     
$newdate = strtotime ( '-3 week' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            
 
Subtracting Months from a date

The following example will subtract 3 months from 1998-08-14. The result will be 1998-05-14. Notice that the only difference in the code is the month statement.

$date = "1998-08-14";                                      
$newdate = strtotime ( '-3 month' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                    
echo $newdate;                                             
 
Subtracting Years from a date

The following example will subtract 3 years from 1998-08-14. The result will be 1995-08-14. Notice that the only difference in the code is the year statement.

$date = "1998-08-14";                                     
$newdate = strtotime ( '-3 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            
 
Adding days, months, weeks and years from a date

There isn’t really much difference from subtracting and adding dates. To add dates, just use any of the examples above and replace the negative (-) with a positive (+) e.g. ‘+3 weeks’
You could also just do:
echo date(“Y-m-j”, strtotime(“1998-08-14 -3 days”));
(sub days, weeks, months, as needed)

This adds 2 days to the current date:
 
$date = date('Y-m-j');                                   
$newdate = strtotime ( '+2 day' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                  
echo $newdate;                                           
 
This adds 2 months to the current date:
 
$date = date('Y-m-j');                                     
$newdate = strtotime ( '+2 month' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                    
echo $newdate;                                             
 
This adds 2 years to the current date:
 
$date = date('Y-m-j');                                    
$newdate = strtotime ( '+2 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

This subtracts 6 hours from the current date:
 
$date = date('Y-m-j');                                    
$newdate = strtotime ( '-6 hour' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

This subtracts 10 minutes from the current date:
 
$date = date('Y-m-j');                                       
$newdate = strtotime ( '-10 minute' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                      
echo $newdate;                                               

If you want to change if from the current date, then simple replace the current date with the desired one…

This adds 1 year to the date 2012-11-25:
 
$date = date('2011-11-25');                               
$newdate = strtotime ( '+1 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

Get the Week Start Date and ENd date 

Consider today is a saturday for the given example

$day = date('w');                                                             // Gives Day of week, returns 6 if it is saturday
$sday = $day - 1;                                                            // I need only working dates mon-sat so 6-1=5 
$eday = 6 - $day;                                                            // Excepting sunday in the list                           
$ws = date('d/m/Y', strtotime('-'.$sday.' days'));            // -5 days to current date that is monday            
$we = date('d/m/Y', strtotime('+'.$eday.' days'));          // + 0 days  to current date that is today - sat      
$lastsunday = date('d/m/Y',strtotime('-'.$day.' days'));  // Gives last week sunday date                           
$comingsunday = date('d/m/Y',strtotime('+'. 7-$day.' days')); // coming sunday                                    

like wise we can get any day of the week , note that the return result is a string

Code for Subtracting a day from given date 

$date = '09/02/2015';
$day_before = date( 'm/d/Y', strtotime( $date . ' -1 day' ) );
echo "<br/><br/>";
$db = date('d/m/Y',strtotime($day_before));

echo $db;

Wednesday, 29 July 2015

STOP loading previous pages when chrome browser started in ubuntu

While Google gets to work fixing the Chrome battery drain issue affecting Windows users, an easy interim solution may help preserve laptop battery life in the meantime.
The fix? Closing the browser when it’s not needed.

Captain Obvious

Historically, closing an application in Windows is straightforward: you click or tap on the ‘x’ window control button.
Depending on your settings, this isn’t always the case with Chrome; closing doesn’t always mean it fully exits. The browser often continues to run in the background on Windows (and Linux) – something you might never notice.

The Reason Why: You

Whether this happens or not depends on the sort of applications and extensions you have installed in Chrome. Some of these will “ask” the browser to stay awake so that they can continue to function; e.g., to deliver notifications of new e-mail messages or keep an active IRC chat alive.
Google makes it easy to tell when background apps are active: just look for the Google Chrome icon in the system tray (bottom right corner of your desktop screen). Click on this emblem to view a list of active tasks and a access a proper ‘Exit’ option.
If want to stop Chrome from running in the background entirely (i.e., so that it always exits when closed), regardless of extension, you can. You just need to tell it to.

How to Stop Chrome Running in the Background

On Windows or Linux click on the Chrome icon in the task bar/system tray, find the ‘Let Chrome run…’ option and click/tap it to disable/toggle the checkmark off.
It’s that simple. 
The behaviour can also be changed through the browser’s main settings page:
  • Click on the Chrome menu (or press Alt+E)
  • Select Settings
  • Click on the link titled ‘Show advanced settings
  • Under the section headed ‘System‘ untick the box next to “Continue running background apps when Google Chrome is closed”
To reenable the feature simply repeat the steps above but reversing the final step.