Specify Number of Records
SELECT TOP/LIMIT/ROWNUM This allows you to specify the number of records to return. Note: that the exact syntax varies depending on the database syntax you are using. We are using MySQL so it would be LIMIT. But we’ll show the basic syntax for all three major varieties first. MySQL SELECT column1, column2,… FROM table_name WHERE…
Read MoreSorting by Multiple Columns
Sometimes you want to be able to sort records by multiple column. In MySQL, you can’t really sort equally but you can sort first by one field and then within that field, sort by another. Let’s take a look at an example. If you wanted to see all students sorted by which language they were…
Read MoreMultiple Conditions in the WHERE Clause
Sometimes you want to look for two conditions – all students who take Chinese and are 16 years old. How do you do this? With the help of the AND, OR and NOT operators. Let’s take a look at what each operator does: AND: displays a record only if meets ALL the conditions OR: displays…
Read MoreHomework: Add Data
In the last homework, you should have created the tables below in phpMyAdmin. Now add at least 5 rows of data per table. Don’t forget to make index fields match!
Read MoreAdd Data to Tables with phpMyAdmin
Creating a table is the first step, now it needs some data. There are many different ways on how to go about getting data in this table. You can import data from another source such as another database table, an Excel spreadsheet or text listing. You can integrate it with a website via a form…
Read MoreThings to Do With Arrays
Properties of Arrays Arrays in PHP have a crazy number of functions! We’ll go over a few of the main ones but if you want to see a full list, check out w3schools.com page! count() function Tells you how many elements are in the array. $kids = array(“Van ”, “Indigo ”, “Jack ”, “Regine ”);…
Read MoreFunctions & Scope
Variable Scope In PHP variables can be declared anywhere in the script. The scope of the variable is the part of the script where the variable can be used. PHP has three different variable scopes: local global static. Global Variables Global: A variable described outside a function has a global scope and can only be…
Read MoreDeleting Records
Last but certainly not least – what if you want to remove records from the database? You do that using the DELETE statement. The basic syntax is as follows: DELETE FROM table_name WHERE condition; And now we will do some more lecturing. If you thought the WHERE clause was important when updating records – it…
Read MoreUpdating Records
Now, you’ve learned how to add new records with SQL – but what about if you want to change an existing record? You do that using the UPDATE statement. The basic syntax is as follows: UPDATE table_name SET field1 = value1, field2 = value2 … WHERE condition; Notice anything interesting about the SQL statement above?…
Read MoreAggregate Functions
We will be using the member table for the examples in this topic. Here it is for reference: MIN This returns the smallest value of the selected field. So if you wanted the youngest student you would use this: SELECT MIN(age) FROM member; This would return this. MAX This would return the highest value…
Read More