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.

Edited by baleeq123
Link to comment
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

Edited by Barand
Link to comment
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

 

can you describe how to explode on comma.

 

thanks alot 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.