al yazid al yazid - 3 months ago 8
PHP Question

Show single record from mysql query database

Firstly, im sorry for my bad english and i am new ini php code.
I am having some problem with my php code. I have some data like this:

name tabel : db_phone
**|PHONE_OS|PHONE |TOTAL|**
|WINDOWS |LUMIA_1 | 5 |
|WINDOWS |LUMIA_1 | 2 |
|WINDOWS |LUMIA_2 | 2 |
|ANDROID |NEXUS_1 | 4 |
|ANDROID |NEXUS_2 | 5 |
|ANDROID |NEXUS_2 | 2 |
|ANDROID |NEXUS_2 | 3 |


my question is :
how to show only one data if it double or more than one.
what should i do if i will make some print out in php like this format:

**|PHONE_OS|PHONE |TOTAL|**
|WINDOWS |LUMIA_1 | 5 |
|__________|_______ | 2 |
|__________|LUMIA_2 | 2 |
|ANDROID |NEXUS_1 | 4 |
|_________|NEXUS_2 | 5 |
|_________|________| 2 |
|_________|________| 3 |


Thanks before,
yahz

Answer

You can do this by GROUP BY clause. The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

Your possible sql query may be like this:

SELECT * FROM db_phone GROUP BY PHONE_OS

We have here grouped them which have same PHONE_OS values.

You can add more columns like this:

SELECT * FROM db_phone GROUP BY PHONE_OS, PHONE

In this query you have grouped them which have same PHONE_OS and same PHONE values.

Comments