Jump to content

Display data in desired order.


baleeq123

Recommended Posts

let me tell you i am new to php and mysql

 

i have mysql database like below

 

 

UID                Student name             Date                            H

433100002      ABC                        24-04-13                       0.5

433100002      ABC                        24-04-13                         1

433100002       ABC                      24-04-13                           0

 

As you have seen UID,Student name,Date are repeating but the value is H is different , so i want to display the data in the form below

 

 

UID                  Student Id               Date             Hour1                Hour2                   Hour3

433100002      ABC                     24-04-13             0.5                  1                            0

 

 

Anybody's help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/277404-display-data-in-desired-order/
Share on other sites

SELECT uid, studentname, date, GROUP_CONCAT(hours) as hours
FROM tablename
GROUP BY uid, studentname, date

which will give this for each student

+-----------+-------------+----------+---------+
| uid       | studentname | date     | hours   |
+-----------+-------------+----------+---------+
| 433100002 | ABC         | 24-04-13 | 0.5,1,0 |
+-----------+-------------+----------+---------+

If you want the hours in separate table cells, explode the field on the commas

SELECT uid, studentname, date, GROUP_CONCAT(hours) as hours
FROM tablename
GROUP BY uid, studentname, date

which will give this for each student

+-----------+-------------+----------+---------+
| uid       | studentname | date     | hours   |
+-----------+-------------+----------+---------+
| 433100002 | ABC         | 24-04-13 | 0.5,1,0 |
+-----------+-------------+----------+---------+

If you want the hours in separate table cells, explode the field on the commas

 

can you describe how to explode on comma.

 

thanks alot 

If you want to show data in ASCENDING order You query should be like this:

 

"SELECT * FROM `TABLE_NAME` ORDER BY `H`"  ;

 

 

If you want to show one row only then limit query to 1

 

"SELECT * FROM `TABLE_NAME` ORDER BY `H`"  LIMIT 1;

I want UID, Name, date should come one and H should contain all values like below

 

 

UID                  Student Id               Date                 H                       H                      H

433100002      ABC                     24-04-13             0.5                  1                            0

I want UID, Name, date should come one and H should contain all values like below

 

 

UID                  Student Id               Date                 H                       H                      H

433100002      ABC                     24-04-13             0.5                  1                            0

 

I've just shown you how - what are you stuck on now?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.