This tutorial will show you how to get records in your table in database to show on your PHP files. This SQL statement has many options.
Syntax : Simple select statement. Select all columns from table.
select * from table_name;
Syntax :Select some columns from table.
select column_name1, column_name2, ... from table_name;
Syntax :Select from table with "where" statement. There are some different when you need the result. For Equal between record and value use "=". For Not Equal between record and value use "<>" or "!=". For just look like between record and value use "like", and "%" sign is using for take the place of some objects before or after specified value.
select * from table_name where column_name='value';
select * from table_name where column_name<>'value';
select * from table_name where column_name like '%value%';
Syntax :Select from table with "order by" statement. By default the result is sorted in ascending order or you can put asc directly into this command. To get a descending order you just change the asc with desc.
select * from table_name order by column_name;
select * from table_name order by column_name asc;
select * from table_name order by column_name desc;
Syntax :Select from table with "limit" statement. This statement need two number after like this "limit 0,5". The first number is for specify starting record (starting at 0) and plus to the next records by 5 times. That means you have get 5 records.
select * from table_name limit number1, number2;
There are more options in select command not included in this tutorial. This is the statement rules for select statement;
Syntax :
SELECT columns FROM table_name [WHERE condition] [ORDER BY order_type] [LIMIT limit_criteria];
In this tutorial create 1 file (select.php)
• select.php
This file will show you how to use the select statement and output the records with while loop in PHP. You must to put some records to table "phonebook" before. If you haven't done, go to Insert Record.
Browse "select.php" by go to http://localhost/select.php.