text: 
  SELECT
    users.id as val,
    users.name as txt,
    users.img
  
  FROM
    courses
      LEFT JOIN enrollments ON
        enrollments.id = $u[id] AND enrollments.course = courses.id AND
        enrollments.status = 1 AND enrollments.history = 0 AND
        enrollments.sdate <= $stamp AND (enrollments.edate > $stamp OR enrollments.edate = 0)
      JOIN lecturers ON lecturers.course = courses.id AND lecturers.status = 1 AND lecturers.history = 0
      JOIN users ON users.id = lecturers.id AND users.type = 'lecturer' AND users.blocked = 0 AND users.deleted = 0
  
  WHERE
    (enrollments.allow = 1 OR (courses.public = 1 AND enrollments.allow IS NULL)) AND
    courses.deleted = 0
  
  GROUP BY
    users.id
    
  ORDER BY
    users.name,
    users.stamp,
    users.id;