Jump to content

Order by Priority


jimmyoneshot

Recommended Posts

I have a page in my site which has a list of teachers I want them to be organised in a very speific way. Here is the query I have now that gets all the teachers.

 

$query_getteachers = "SELECT * FROM staffs WHERE type_id = 1 ORDER BY is_featured DESC, is_department_head DESC, join_date DESC LIMIT $start, $limit";

 

"is_featured" is a boolean (1 = true, 0 = false) which states whether the teacher is the featured teacher or not

"is_department_head" is a boolean (1 = true, 0 = false) which states whether the teacher is a department head or not

"join_date" is a date field which states when the teacher joined

"$start" and "$limit" are dynamic numeric values used for pagination purposes

 

Now the thing is I want it so that.

 

- The featured teacher is at the top (there is only 1 featured teacher)

- The department heads follow next ordered by their join date

- ONLY once the featured teacher and department heads have all been listed the rest of the teachers will be shown ordered by their creation date

 

This would usually be easily split into 3 queries but the need for pagination has complicated this somewhat so I need it to be done in one query. Is this doable and if so how? Because as the query is now my results all get mixed together. Thanks for any help in advance

Link to comment
https://forums.phpfreaks.com/topic/225345-order-by-priority/
Share on other sites

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.