×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
IF has three parameters:
1 - Condition.
2 - Executes if the condition evaluates to true
3 - Executes if the condition evaluates to false IF(condition , [expression when true], [expression when false]);
Returns false because the first parameter 0 evaluates to falseSELECT IF(0, 'true', 'false') AS Boolean
Simple IF statement in SELECT clauseSELECT *,
IF(points>=90, "Brilliant", "Lazy") AS class
FROM `students`
ORDER BY points DESC
Nested IF conditional statement.
Categorizes students based on their pointsSELECT *,
IF(points>=90, "Brilliant", IF(points>=80, "Gold", IF(points>=60, "Silver", "Lazy"))) AS class
FROM `students`
ORDER BY points DESC
Sub-query inside IF.
Highlights the student with highest pointsSELECT *,
IF(points>=90, IF(points=(SELECT MAX(points) FROM students), "Highest", "Brilliant"), IF(points>=80, "Gold", IF(points>=60, "Silver", "Lazy"))) AS class
FROM `students`
ORDER BY points DESC
IF statement in WHERE clause.
Checks mail if it is not empty otherwise checks mail2 SELECT *
FROM `students`
WHERE IF(LENGTH(mail), mail, mail2) LIKE '%gmail.com%'let numbers = [10, 100, 1000]
let doubled = numbers.map(function(x){
return x * 2
})
document.write(doubled)
Alternative arrow function:let doubled = numbers.map((x) => { return x * 2 })
If it's only a single line we don't need curly brackets and the keyword return let doubled = numbers.map((x) => x * 2);
If the arrow function has only one parameter, it does not need parentheses:let doubled = numbers.map(x => x * 2);
Note: We only need parentheses if we had zero or more than one parametersSELF JOIN SELECT
s1.*,
s2.first_name
FROM `students` s1
JOIN `students` s2 ON s2.santa_id = s1.id
This type of join is often used when we have tree structure in a table.
Note: alias is mandatory in SELF JOINalias to tables or table columns.
In this example table column first_name will be displayed as student_name SELECT
id,
first_name AS student_name
FROM students
The keyword AS is optional, but it's better to use it, because the query is much more readable.
The following query returns the same resultSELECT
id,
first_name student_name
FROM students
We can use alias in ORDER BY clause to order the resultSELECT *, price * quantity AS total
FROM `orders`
ORDER BY total DESC
If alias is given to table, column of the table can be accessed by the alias followed by . SELECT
s.id,
s.first_name
FROM `students` s
In SELF JOIN alias is required, because MySQL needs to treat the tables as different tablesSELECT
s1.*,
s2.first_name
FROM `students` s1
JOIN `students` s2 ON s2.santa_id = s1.id
quotes or backticks can be used in alias.
Possible options: single quote ', double quote " or backtick ` SELECT
id,
first_name AS 'student_name'
FROM
students
Advantage of using quotes is that we can use space separated names in aliasSELECT
first_name,
last_name,
(points + 10) * 2 AS 'points calculated'
FROM students$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
// Returns the JSON representation of a value (pretty printed)
echo json_encode($arr, JSON_PRETTY_PRINT);Result of the above code{
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5
}
The following example shows how the PHP objects can be converted into JSONclass Emp {
public $name = "";
public $hobbies = [];
public $birthdate = "";
}
$e = new Emp();
$e->name = "sachin";
$e->hobbies = ["sport", "reading"];
$e->birthdate = date('Y-m-d', strtotime('2015-11-18'));
echo json_encode($e);The above code will produce the following result{"name":"sachin","hobbies":["sport","reading"],"birthdate":"2015-11-18"}
Decoding JSON in PHP (json_decode)
The following example shows how PHP can be used to decode JSON objects$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
// Decoding into an object
var_dump(json_decode($json));
// Decoding into an array
var_dump(json_decode($json, true));While executing, it will produce the following resultobject(stdClass)#1 (5) {
["a"]=> int(1)
["b"]=> int(2)
["c"]=> int(3)
["d"]=> int(4)
["e"]=> int(5)
}
array(5) {
["a"]=> int(1)
["b"]=> int(2)
["c"]=> int(3)
["d"]=> int(4)
["e"]=> int(5)
}1. XML Syntactical whitespace - is whitespace required by the XML in order to delimitate XML constructs.
2. Insignificant Whitespace - is whitespace, that is not considered part of an element, if two elements are separated by just whitespace its considered insignificant.
3. Significant Whitespace - is whitespace that XML element attribute contains.this inside driveCar() function refers to the global window object.
Global variables firstName and lastName are added to the window object.
That is why they are visible using the keywordfirstName = "Jack"
lastName = "Ma"
function driveCar() {
document.write(this.firstName + ' ' + this.lastName + ' is driving a car<br/>')
}
driveCar()
If we call the same function using call function, this will refer to the object that will be passed.
In this case: john objectlet john = {
firstName: 'John',
lastName: 'Doe'
}
function driveCar() {
document.write(this.firstName + ' ' + this.lastName + ' is driving a car<br/>')
}
driveCar.call(john)- Comment must appear after XML declaration.
- Comment may appear anywhere in a document
- Comment must not appear within attribute values.
- Comment cannot be nested inside the other comment.true but in PHP it evaluates to false if ("0") {
}.mt-3 - margin-top
.mr-3 - margin-right
.mb-3 - margin-bottom
.ml-3 - margin-left
.mx-3 - margin-left, margin-right
.my-3 - margin-top, margin-bottom
.m-3 - margin-top, margin-bottom, margin-left, margin-right
The same for padding properties:
.pt-3 - padding-top
.pr-3 - padding-right
.pb-3 - padding-bottom
.pl-3 - padding-left
.px-3 - padding-left, padding-right
.py-3 - padding-top, padding-bottom
.p-3 - padding-top, padding-bottom, padding-left, padding-right