php - how to search in multiple table? -


i have 2 tables medicalhistory , patient in medicalhistory have fields name doctorid , patientid , in patient ihave patientid, firstname,middlename,lastname

as of query filter 1 table , patientid medicalhistory.

$dids = $_session["doctorid"]; if(isset($_post["btnsrch"])&& ($_post["textbox"]!="")){    $pid = $_post["textbox"];     $pid= mysqli_real_escape_string($_post["textbox"]);     $query2= mysqli_query($link,"select distinct patientid medicalhistory doctorid='". $dids ."' or patientid='". $pid ."'" );  } 

my problem how query firstname middlename , lastname query name have records on doctor in medicalhistory ?

$query2= mysqli_query($link,"select p.patientid,p.firstname,p.middlename,p.lastname  patient p  inner join medicalhistory pa on (p.patientid = pa.patientid)  pa.patientid='".$pid."'" );  

this code modified:

$dids = $_session["doctorid"]; if(isset($_post["btnsrch"])&& ($_post["textbox"]!="")){     $pid = $_post["textbox"];     $pid= mysqli_real_escape_string($_post["textbox"]);      $query2= mysqli_query($link,"select p.patientid, p.firstname, p.middlename, p.lastname,pa.doctorid,pa.evaluation patient p inner join medicalhistory pa on (p.patientid=pa.patientid) pa.patientid='".$pid."'" ); } 

sample output:

mysql> select p.id,p.first,p.last, p.middle,pa.id,pa.evalution test1 p left join test pa on (p.id=pa.id) p.first='dan' , p.id=4 , p.last='smi th'; +----+-------+-------+----------+----+-----------+ | id | first | last  | middle   | id | evalution | +----+-------+-------+----------+----+-----------+ |  4 | dan   | smith | chandran |  4 | sick      | +----+-------+-------+----------+----+-----------+ 1 row in set (0.00 sec) 

Comments