Wednesday, February 10, 2010

PHP: functions

In this tutorial I will show some helpful codes where you can get the data from the SQL using a the PHP


SELECT * FROM table1 WHERE column1 LIKE '%a';
-displays all the data that ends with letter 'a'

SELECT * FROM table1 WHERE column1 LIKE '%a%';
-displays all the data with letter 'a'

SELECT * FROM table1 WHERE column1 LIKE 'a%';
-displays all the data that starts with letter 'a'

SELECT * FROM table1 WHERE column1 LIKE '_ _ _ _';
-displays all the data but limits the displayed data to only 4 characters

SELECT * FROM table1 WHERE column1 IN ("an", "be", "cy");
-displays all the data that starts with 'an', 'be' and 'cy'

SELECT * FROM table1 ORDER BY name;
-displays all the data but sorted by its 'name'

SELECT * FROM table1 LIMIT 20;
-displays only the first 20 data

SELECT COUNT(*) FROM table1 WHERE column1 = 'asdf';
-displays the number of data that have 'asdf' entry

SELECT MAX(column1) FROM table1;
-determine what data have the highest entry

No comments:

Post a Comment