The SQL WHERE Clause
The WHERE
clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
Example
Select all customers from Mexico:
SELECT * FROM Customers
WHERE Country='Mexico';
The WHERE
clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
Select all customers from Mexico:
SELECT * FROM Customers
WHERE Country='Mexico';
The SELECT DISTINCT
statement is used to return only distinct (different) values.
Select all the different countries from the “Customers” table :
SELECT DISTINCT Country FROM Customers;
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
The SELECT
statement is used to select data from a database.
Return data from the Customers table :
SELECT CustomerName, City FROM Customers;
Most of the actions you need to perform on a database are done with SQL statements.
SQL statements consist of keywords that are easy to understand.
The following SQL statement returns all records from a table named “Customers”:
Select all records from the Customers table:
SELECT * FROM Customers;
In this tutorial we will teach you all about the different SQL statements. Continue reading SQL Syntax
JSONP is a method for sending JSON data without worrying about cross-domain issues.
JSONP does not use the XMLHttpRequest
object.
JSONP uses the <script>
tag instead.
JSONP stands for JSON with Padding.
Requesting a file from another domain can cause problems, due to cross-domain policy.
Requesting an external script from another domain does not have this problem.
JSONP uses this advantage, and request files using the script tag instead of the XMLHttpRequest
object. Continue reading Javascript – JSONP
JSON can very easily be translated into JavaScript.
JavaScript can be used to make HTML in your web pages.
Make an HTML table with data received as JSON:
const dbParam = JSON.stringify({table:"customers",limit:20});
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
myObj = JSON.parse(this.responseText);
let text = "<table border='1'>"
for (let x in myObj) {
text += "<tr><td>" + myObj[x].name + "</td></tr>";
}
text += "</table>"
document.getElementById("demo").innerHTML = text;
}
xmlhttp.open("POST", "json_demo_html_table.php");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("x=" + dbParam);
A common use of JSON is to read data from a web server, and display the data in a web page.
This chapter will teach you how to exchange JSON data between the client and a PHP server.
PHP has some built-in functions to handle JSON.
Objects in PHP can be converted into JSON by using the PHP function json_encode(): Continue reading Javascript JSON PHP
A common use of JSON is to exchange data to/from a web server.
When receiving data from a web server, the data is always a string.
Parse the data with JSON.parse()
, and the data becomes a JavaScript object.
If you have data stored in a JavaScript object, you can convert the object into JSON, and send it to a server:
const myObj = {name: "John", age: 31, city: "New York"};
const myJSON = JSON.stringify(myObj);
window.location = "demo_json.php?x=" + myJSON;
This is a JSON string:
'["Ford", "BMW", "Fiat"]'
Inside the JSON string there is a JSON array literal:
["Ford", "BMW", "Fiat"]
Arrays in JSON are almost the same as arrays in JavaScript.
In JSON, array values must be of type string, number, object, array, boolean or null.
In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.
This is a JSON string:
'{"name":"John", "age":30, "car":null}'
Inside the JSON string there is a JSON object literal:
{"name":"John", "age":30, "car":null}
JSON object literals are surrounded by curly braces {}.
JSON object literals contains key/value pairs.
Keys and values are separated by a colon.
Keys must be strings, and values must be a valid JSON data type:
Each key/value pair is separated by a comma.
It is a common mistake to call a JSON object literal “a JSON object”.
JSON cannot be an object. JSON is a string format.
The data is only JSON when it is in a string format. When it is converted to a JavaScript variable, it becomes a JavaScript object.