Page 1 of 1

Vairables from different tables

Posted: Tue Apr 21, 2009 7:52 am
by inf
I am trying to get rows from different tables in the database but I don't know how to do that.

Basically..

doctor row in people table = doctor id in doctor table
i would like the statement to say, Today your appointment is with Doctor Sean Lister

the rows in the doctors table are
id
firstname
secondname

This is my code so far...

Code: Select all

<?
header ("Content-Type: utf-8");
include("opendbinclude.php");
 
 
$result = mysql_query("SELECT * FROM people");
 
 
while($row = mysql_fetch_array($result))
  {
if ($_REQUEST['text'] == $row['first_name'] . " " . $row['surname']  . " " . $row['postcode'])
 
header ("Location: http://localhost:8800/?phonenumber=" . $_REQUEST['sender'] . "&text=" . urlencode("Welcome to Sunderland Hospital. Today your appiontment is with " . $row['doctor']  . " at " . $row['time']  . " in room " . $row['room']  . " to get there please follow these directions; " . $row['direction']));
mysql_query("INSERT INTO logs (name, status) VALUES ('" . $row['first_name'] . " " . $row['surname'] . "', 'Signed In')");
 
}
 
?>

Any help is much appreciated!!

Re: Vairables from different tables

Posted: Tue Apr 21, 2009 8:03 am
by it2051229
I dont know how your problem is related with the code you have provided.. so you have problems with retrieving data from multiple tables? I dont kind of understand your problem but you can show the structure of your tables in the database...

Re: Vairables from different tables

Posted: Tue Apr 21, 2009 11:24 am
by inf
Image

Re: Vairables from different tables

Posted: Tue Apr 21, 2009 8:30 pm
by inf
Sorry to bump but does anyone have a quick solution for this?

Re: Vairables from different tables

Posted: Tue Apr 21, 2009 10:11 pm
by it2051229
the SQL statement that I can provide is:

Code: Select all

 
"SELECT doctors.firstname, doctors.surname FROM doctors, people WHERE doctors.ID = people.doctor AND people.ID = (Whoever the patient you are refering to)"
 

Re: Vairables from different tables

Posted: Wed Apr 22, 2009 7:37 am
by miro_igov
Hmm the answer is JOIN