php - Make a select query from two table with where clause. -


i have 2 variables $code , $name. $code have tutor's code or institute's code and$name have tutor's name or institute's name.

this way names come $code , $name

// check tutor or institute if ( $tutorcode && $tutorname) {     $code = $tutorcode;     $name = $tutorname; } elseif ( $institutecode && $institutename) {     $code = $institutecode;     $name = $institutename; } 

my problem need email address contact table according $code , $name. need check 2 table tutor , institute belong code , name.

tutor , institute table have contact_id , contact table have contact_id. tutor table have tutor_code , tutor_name.
institute table have institute_code , institute_name

i tried this. can't check in both tables.

$q = "select email tutor        tutor_code = $code , tutor_name = $name" 

hope me. thank you.

you can union both tables

select  email, code, name (     select email, tutor_code code, tutor_name name tutor     union     select email, institute_code  code, institute_name name institute ) sub   code = $code ,         name = '$name' 

or

select  s.*, c.*         (             select  contact_id,                      tutor_code code,                      tutor_name name,                     'tutor' sourcetbl                tutor               tutor_code = $code ,                     tutor_name = '$name'             union             select  contact_id,                     institute_code  code,                      institute_name name,                     'institute' sourcetbl                institute               institute_code = $code ,                     institute_name = '$name'         ) s         inner join contact c             on s.contact_id = c.contact_id 

keep mind return duplicate record if both records exists on both table because of specifying all in union. if want unique records, remove all.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -