i am messing around with a couple scripts and am having a little issues when it comes to joins
[code] $result = mysql_query("SELECT p.name, m.name, m.dose FROM patients p, meds m WHERE p.med_id = m.med_id ") or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("Name: %s Med %s
", $row[‘p.name’], $row[‘m.name’]);[/code]
now what i want it to do is print the patients name and the corisponding pill
I get :
Name: Med:
Name: Med:
Name: Med:
Name: Med:
now what i did notice is that when i change the
$row[‘p.name’] to $row[0] it returns the Patients name
$row[‘m.name’] to $row[1] it returns the Meds name
[code] $result = mysql_query("SELECT p.name, m.name, m.dose FROM patients p, meds m WHERE p.med_id = m.med_id ") or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("Name: %s Med: %s
", $row[0], $row[1]);[/code]
I Get which is the result it is suppose to return in the first script
Name: Peggy Med: PillA
Name: Bert Med: PillB
Name: Lisa Med: PillD
Name: Jim Med: PillF
but that is no help since this query is going to be more complex with more fields from both the patient and med so i need to be able to select field name
thanks in advance
Hershal