Data types in Mysql / Mariadb

php-training-in-gurgaon
Numeric Data Types: INT (Integer): Int data type represents an integer of normal size. So simply it can used to store numeric value. There are also BIGINT, MEDIUMINT, SMALLINT and TINYINT which represent different range of integer values. DECIMAL: Decimal data type represents numbers with specific floating values. Maximum permitted value is 65 and maximum decimals are 30. There are also FLOAT and DOUBLE to store numeric values with floating point. BOOLEAN:  This data type associates a value 0 with ―”false”, and a value 1 with true. Date and Time Data Types:  DATE: The DATE data type represents a date in “YYYY-MM-DD” format. TIME: The TIME data type represents a time in "HH:MM:SS" format. DATETIME: The DATETIME data type represents date and time in “YYYY-MM-DD HH:MM:SS” format. TIMESTAMP: This data…
Read More

The do-while loop

php-training-in-gurgaon
Difference Between while and do…while Loop: With a while loop, the condition to be evaluated is tested at the beginning of each loop statement, so if the conditional expression evaluates to false, the loop will never be executed. With a do-while loop, on the other hand, the loop will always be executed once, even if the conditional expression is false, because the condition is evaluated at the end of the loop statement. Example: <?php $i = 1; do { $i++; echo  $i . "<br>"; } while($i <= 3); ?>  Output: 2 3 4
Read More

The While Loop

php-training-in-gurgaon
A While loop is used when we have to repeat a set of statements as long as the condition is false. It could be the best where number of repetition is not known earlier or in advance. It can be explain in plain English as "Keep doing something until a condition is true". Syntax: while (condition) { //  Set of statements goes here; } Example <?php $ct=5; while($ct<=50) { echo  $ct . "<br>"; $ct = $ct+5; } ?> Output: 5 10 15 20 25 30 35 40 45 50 The do…while loop example: <?php $i = 1; do { $i++; echo  $i . "<br>"; } while($i <= 3); ?>  Output: 2 3 4 Difference Between while and do…while Loop: With a while loop, the condition to be evaluated is tested…
Read More

PHP -Building Blocks

php-training-in-gurgaon
If –else statements: if…else statement – executes set of codes if a condition is true and another code if the condition is false Within a statement, if a certain condition is true, then something happens. Otherwise, something else happens. We can continue adding else statements as many times as we need. So, within PHP statement, we first define the variable and then set up the conditional statements like this: Syntax: if (condition) code to be executed if condition is true; elseif (condition) code to be executed if condition is true; else code to be executed if condition is false; Example 1: <?php $avg = 50 if ($avg>60) { echo "You have a good score"; } else { echo "Score is less than average"; } ?> Example 2:  <?php $status =…
Read More

The For Loop

php-training-in-gurgaon
PHP for loop can be used to traverse set of code for the specified number of times. For example if you want to repeat something ten or twenty times. It should be used if number of iteration is known otherwise I recommend you to use while loop. Syntax: for (Initialization; Condition; Progressive) { //set of statements to be executed; } Parameters: Initialization: Initialize the loop counter value Condition: Check for condition. If it evaluates to TRUE, the loop continues. If FALSE then the loop ends. Progressive: Increase / Decrease the loop counter value Example: for($var=1; $var<=20; $var=$var+1) { echo $var ." "; } Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Example: to display 1st 20 natural…
Read More

PHP Superglobals

php-training-in-gurgaon
We already learned about variables, but there are some Readymade or predefined keywords in PHP that can be used without you having to create them first. Predefined or Superglobals variables are used to provide information from and about the web server, the web browser, and the user. There are several types of Super Global Variables:- $_GET - Is used to pass data through URL. Example: http://websjyoti.com?id=2 $_POST - Is used to pass data to server by hiding from URL. $_REQUEST – Is the combination of $_GET, $_POST, and $_COOKIE. $_SESSION - is used to maintain session and data from Local machine to Server. $_COOKIE – Is used to save/get user data on same machine in browser cookies. $_SERVER – Is an associative array which is used to know server information…
Read More

Arrays in PHP

php-training-in-gurgaon
An array is a data structure that stores similar type of values in a common variable. Arrays are also called homogeneous data type. For example if you want to store 50 numbers then instead of defining variables it is easy to define an array with size of 50. In PHP, the array() function is used to create an array Arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero. $x=array("laxmi","hirdesh","rahim","ashu","amit"); // To count number of elements stored in array x echo count($x); // To populate value from any specific index or position //echo $x[1]; // output – Hirdesh // To print all elements in array x - using for-each loop echo " <br>Names are :"; foreach ($x…
Read More

PHP – Date / Time Functions

php-training-in-gurgaon
When working in any programming language, dealing with dates and time is a simple task. That is, until time zones have to be supported. PHP's time () function gives you all the information that you need about the current date and time. It requires no arguments but returns an numeric value. If you will call to time() function which will return a set of numeric values which is difficult to understand. So to make it easy we can have time format along with the date() function. <?php $today = date("d/m/Y"); echo "Today is ".$today; ?> We can use different time format with separator like d-m-Y, d.m.Y and so on. Display Current Date and Time:  We can use the following characters to format the time string: <?php echo date("h:i:s") . "<br>";…
Read More