php - How do I embed a select in a select or call another function from a select? -


i have select statement this:

    select c.id courseid, u.id userid           mdl_user_enrolments ue     join mdl_enrol e on e.id = ue.enrolid     join mdl_user u on u.id = ue.userid     join mdl_course c on c.id = e.courseid 

i have piece of data want not have direct relationship current tables. have been calling function in output loop,

function getlastcourseaccessbyuser($courseid, $userid){ global $db; return     $db->get_record_sql('     select from_unixtime(time, "%m/%d/%y") ftime     mdl_log     course = '.$courseid.' , userid = '.$userid.'      order time desc     limit 1 '); 

}

but rather data once, , not call db.

i trying this:

            select c.id courseid, u.id userid              (                select from_unixtime(time, "%m/%d/%y") ftime                mdl_log                course = c.id , userid = u.id              )  lastaccessdate                    mdl_user_enrolments ue          join mdl_enrol e on e.id = ue.enrolid          join mdl_user u on u.id = ue.userid          join mdl_course c on c.id = e.courseid 

or, call function directly sql this:

        select c.id courseid, u.id userid,               '.getlastcourseaccessbyuser(c.id,u.id).' lastaccessdate               mdl_user_enrolments ue         join mdl_enrol e on e.id = ue.enrolid         join mdl_user u on u.id = ue.userid         join mdl_course c on c.id = e.courseid 

thank you.

select c.id courseid, u.id userid, from_unixtime(t.time, "%m/%d/%y") ftime           mdl_user_enrolments ue     join mdl_enrol e on e.id = ue.enrolid     join mdl_user u on u.id = ue.userid     join mdl_course c on c.id = e.courseid     join mdl_log t on t.course = c.id , t.userid = u.id 

you can put , and or clauses in join in mysql can join on both conditionals. though may want make outer join won't fail entire query if conditionals aren't met

otherwise sub select option should work (this one)

 select c.id courseid, u.id userid              (                select from_unixtime(time, "%m/%d/%y") ftime                mdl_log                course = c.id , userid = u.id              )  lastaccessdate                    mdl_user_enrolments ue          join mdl_enrol e on e.id = ue.enrolid          join mdl_user u on u.id = ue.userid          join mdl_course c on c.id = e.courseid 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -