Vairables from different tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inf
Forum Newbie
Posts: 5
Joined: Mon Apr 20, 2009 7:52 pm

Vairables from different tables

Post 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!!
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Vairables from different tables

Post 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...
inf
Forum Newbie
Posts: 5
Joined: Mon Apr 20, 2009 7:52 pm

Re: Vairables from different tables

Post by inf »

Image
inf
Forum Newbie
Posts: 5
Joined: Mon Apr 20, 2009 7:52 pm

Re: Vairables from different tables

Post by inf »

Sorry to bump but does anyone have a quick solution for this?
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Vairables from different tables

Post 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)"
 
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: Vairables from different tables

Post by miro_igov »

Hmm the answer is JOIN
Post Reply