Posts

PHP array

Image
  An array stores multiple values in one single variable. In PHP, the array() function is used to create an array. Example: <?php $pets = array ( "dog" , "cat" , "rabbit" ); echo $pets [ 0 ] . "," . $pets [ 1 ] . "," . $pets [ 2 ]; ?> Output: dog,cat,rabbit An array is a special variable, which can hold more than one value at a time. If you have a list of student names, storing the names in single variables could like this, $name1 = "Peter" $name2 = "Mickle" $name2 = "Bravo" However, what if you want to loop through the names and find a specific one? And what if you had 3 names, but 1000? The solution is to create an array . An array can hold many values under a single name, and you can access the values by referring to an index number. There are three different kind of arrays. Numeric array – Arrays with a numeric index Associative array – Arrays with named keys

PHP Code for get Client IP Address

Image
You can get the client IP address from below code. Syntax: <?php //whether ip is from share internet if ( ! empty ( $_SERVER [ 'HTTP_CLIENT_IP' ] ) ) { $ipaddress = $_SERVER [ 'HTTP_CLIENT_IP' ] ; } //whether ip is from proxy elseif ( ! empty ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { $ipaddress = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; } //whether ip address is from remote address else { $ipaddress = $_SERVER [ 'REMOTE_ADDR' ] ; } echo $ipaddress ;   ?>

PHP Code for Calculating the Length of a String

The strlen() function is used to calculate the number of characters inside a string. It also includes the blank spaces inside the string. Example:   <?php     $string = "Welcome to PHP Coding Help Blog" ;     echo strlen ( $string );  ?>  //Output: 31

Find Duplicate Records in MySQL Table

Image
In this post, you will learn how to find duplicate values of one or more columns in MySQL table. Find duplicate values in one column The find duplicate values in on one column of a table, you use follow these steps:- First, use the GROUP BY clause to group all rows by the target column, which is the column that you want to check duplicate. Then, use the COUNT() function in the HAVING clause to check if any group have more than 1 element. These groups are duplicate. Syntax:   SELECT    col,     COUNT (col)   FROM    table_name   GROUP BY col   HAVING COUNT (col) > 1; Find duplicate values in multiple columns Sometimes, you want to find duplicate rows based on multiple columns instead of one. In this case, you can use the following query:- Syntax:   SELECT    col1, COUNT (col1),    col2, COUNT (col2),    .....   FROM    table_name   GROUP BY    col1,    col2,    .....   HAVING