baleeq123 Posted April 29, 2013 Share Posted April 29, 2013 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 More sharing options...
Barand Posted April 29, 2013 Share Posted April 29, 2013 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 Link to comment https://forums.phpfreaks.com/topic/277404-display-data-in-desired-order/#findComment-1427086 Share on other sites More sharing options...
baleeq123 Posted April 29, 2013 Author Share Posted April 29, 2013 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 https://forums.phpfreaks.com/topic/277404-display-data-in-desired-order/#findComment-1427090 Share on other sites More sharing options...
Barand Posted April 29, 2013 Share Posted April 29, 2013 see manual - explode eg $hoursArray = explode(',', $row['hours']); foreach ($hoursArray as $hour) { echo "<td>$hour</td>"; } Link to comment https://forums.phpfreaks.com/topic/277404-display-data-in-desired-order/#findComment-1427091 Share on other sites More sharing options...
baleeq123 Posted April 30, 2013 Author Share Posted April 30, 2013 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 https://forums.phpfreaks.com/topic/277404-display-data-in-desired-order/#findComment-1427238 Share on other sites More sharing options...
Barand Posted April 30, 2013 Share Posted April 30, 2013 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 https://forums.phpfreaks.com/topic/277404-display-data-in-desired-order/#findComment-1427241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.