Russia Posted July 1, 2013 Share Posted July 1, 2013 (edited) I made this query so it combines 2 tables into one so It can get the name of the office and insurance company instead of the number variable it is but its not working. $values = mysql_query("SELECT pat_id,pat_lname,pat_fname,pat_date,pat_loc,pat_ins,pat_show FROM patients INNER JOIN offices ON office_id = pat_loc INNER JOIN insurance ON ins_id = pat_ins "); How the offices database looks like: How it looks when exporting: I am trying to get it to show the name Hackensack instead of a 2 for the location in pat_loc when it exports. How can I get that to work?Here is the whole statement: $values = mysql_query("SELECT pat_id,pat_lname,pat_fname,pat_date,pat_loc,pat_ins,pat_show FROM patients INNER JOIN offices ON office_id = pat_loc INNER JOIN insurance ON ins_id = pat_ins "); while ($rowr = mysql_fetch_row($values)) { for ($j = 0; $j < $i; $j++) { $csv_output .= $rowr[$j] . ", "; } $csv_output .= "\n"; } Edited July 1, 2013 by Russia Quote Link to comment Share on other sites More sharing options...
denno020 Posted July 2, 2013 Share Posted July 2, 2013 I've only just started playing with join statements, but maybe you could give this a try: SELECT pat_id,pat_lname,pat_fname,pat_date,pat_loc,pat_show, (SELECT office_name FROM offices WHERE offices.office_id = patients.pat_ins) AS name_office FROM patients I don't have your database code, so I can't really test that, but the idea is that the SELECT within the parenthesis will grab the office_name from the table offices where office_id in offices matches pat_ins from patients (I think I got the fields right for what you were after?), and put it into the results as name_office. But like I said, I could be way off base here. Hopefully that'll give you something else to look into. Denno Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.