I’m having an issue with a MySQL query and PHP array. It’s been a while since i’ve dealt with either, so I could use a little help. I’ve got a medical group with clinics in several cities. On their site, they want a search form so that users can search by several criteria and the results show physicians name and which clinic(s) they operate in. Some physicians operate in more than one clinic. The problem I’m running into, when I query without specifying a clinic, those doctors who work in more than one clinic appear multiple times – one for each clinic they work in. I want to know if I can have their names appear once, with multiple cities entries listed.
here’s my basic MySQL database set up:
**physicians_tbl**
*physician_id physician_name*
0 John Doe
1 Jane Smith
2 Bill Johnson
**locations_tbl**
*locations_id city*
0 Jackson
1 Vicksburg
2 Meridian
3 Madison
**physicians_location_tbl**
*physician_location_id physician_id locations_id*
0 1 0
1 1 1
2 0 2
3 2 3
my query is:
$physician_result = @mysql_query ("SELECT DISTINCT physicians_tbl.physician_id, city, name
FROM physicians_tbl, locations_tbl, physicians_locations_tbl
WHERE physicians_locations_tbl.locations_id = locations_tbl.locations_id
AND physicians_locations_tbl.physician_id = physicians_tbl.physician_id
AND name LIKE '$last_name'
ORDER BY name DESC", $connection) or die("error querying database");
echo '<table><tr>';
while($result_ar = mysql_fetch_assoc($physician_result)){
echo '<td width="33%"nowrap>'.$result_ar['name'].', '. $result_ar['city'].'</td>';
}
echo '</tr></table>';
So, if I search for attorney by last name ($last_name) “Smith” without specifying a city, I get two rows in my while loop:
Jane Smith, Jackson
Jane Smith, Vicksburg
is there a way to make to condense my array and/or my query, so that I get one row with name, city [0], city[1]:
Jane Smith, Jackson, Vicksburg
any help is greatly appreciated,
rvt