In this post becoding.tk will teach you how to display the data in a database table mysql. To learn more about creating one database and then entered into the database.
(A database created by admin named "becoding")
then create a table with a structure like the one below with the name table "items".
Command:
items_id | : | the unique code of an item. |
items_name | : | is the name of that item. |
price | : | the price of an item. |
reg_date | : | is the date the item list. |
then insert the following data:
Item_Id | Items_Name | Price | Reg_Date |
A001 | NEXUS 7 | 3200000 | 2016-07-02 |
A002 | SAMSUNG GALAXY J7 | 4500000 | 2016-07-02 |
A003 | ASUS ZENFONE 4C | 1500000 | 2016-07-04 |
A004 | ASUS ZENFONE 4 | 1100000 | 2016-08-01 |
A005 | ASUS ZENFONE SELFIE | 3500000 | 2016-08-02 |
ScreenShot: Create table and Insert data [Click Here]
Displaying all the data in the table (without criteria)
To display the existing data ditable then the command is
select * from table_name;
notes:
* -> all field
For example, we will show all the data we have filled out earlier in the table items,
then the command is:
select * from items;
ScreenShot: Select all [Click Here]
Whereas if we only want to show the data of field items_id and items_name ,then the command:
select items_id,items_name from items;
ScreenShot: Select all 2 [Click Here]
Showing particular the data in the table (criteria)
Before we have to show all the data in the table, so now we will bring certain data
with a criteria or rules. for it is basically the command 'where' the structure as follows:
select * from table_name where criteria;
Several criteria that you can use is
1. The search for data with a specific name.
2. Search for the data with a certain ratio.
1. The search for data with a specific name.
Basic commands in this criterion is "like",with writing pattern:
field_name Like ('X')
X is the rule as follows:
A% | : | the data front the letter A |
%A% | : | Data containing the letters A |
%A | : | the data behind the letter A |
For example if we want to display the data items named "ASUS" then the command is
select * from items where items_name like ('ASUS%');
For example if you want to display data items containing the letter "E" then the command is
select * from items where items_name like ('%E%');
For example if you want to show the data items that letter behind it is "7", the command is
select * from items where items_name like ('%7');
ScreenShot: Like command [Click Here]
2. Search for the data with a certain ratio.
Command in this criterion is an operator berbandingan as>,> =, <, <=, =, <>.
explanation:
> | : | Greater than |
>= | : | Greater than or equal to |
< | : | Less than |
<= | : | Less than or equal to |
= | : | equal to |
<> | : | Not or is not equal to |
For example, we will display the data items that are not items "NEXUS 7", then the command
select * from items where items_name<>'NEXUS 7';
For example, we will display the data items that cost over 1500000 then the command
select * from items where price>1500000;
ScreenShot: Certain ratio [Click Here]
That's how to display data from a mysql table, until the first lesson here we are today. I hope this article can be useful for you all, thank you for visiting and reading to the end.
Tidak ada komentar:
Posting Komentar