Reputation: 335
I want this type of output to fetch task_name from database like in this format
Task 10 Task 2 Task 3 Task 5........
My Query is
SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '".$studentid."'
AND section_name = 'sm1'
GROUP BY task_name
So I want to output like this..
Task 2 Task 3 Task 5 Task 10........
Upvotes: 0
Views: 692
Reputation: 8476
use this
"SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '1'
AND section_name = 'sm1'
GROUP BY task_name
ORDER BY cast( SUBSTRING( task_name, 5 ) AS unsigned ) ASC"
Upvotes: 1
Reputation: 30488
use this
SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '".$studentid."'
AND section_name = 'sm1'
ORDER BY ltrim(task_name) ASC //order by should come for ordering....
GROUP BY task_name
instead of
SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '".$studentid."'
AND section_name = 'sm1'
GROUP BY task_name
Upvotes: 0
Reputation: 5356
"select task_name,section_name,ref_student_id from scores where ref_student_id = '".$studentid."' and section_name = 'sm1' GROUP BY task_name order by task_name ASC "
Order by Ascending
Upvotes: 0