Reputation: 176
I have created an inner join between 2 Databases as shown below
$result = mysql_query("SELECT gs.gs_users.id,gs.gs_user_objects.user_id, gs.gs_user_objects.imei, gs.gs_objects.imei, gs.gs_objects.lat, gs.gs_objects.lng,
gs.gs_objects.dt_server, gs.gs_objects.name, gs.gs_objects.odometer, dispatch.tablet_dispatch.client_id,
dispatch.tablet_dispatch.destination, dispatch.tablet_dispatch.reg, dispatch.tablet_dispatch.d_name
FROM gs.gs_users
INNER JOIN dispatch.tablet_dispatch ON gs.gs_users.id = dispatch.tablet_dispatch.client_id
INNER JOIN gs.gs_user_objects ON gs.gs_users.id = gs.gs_user_objects.user_id
INNER JOIN gs.gs_objects ON gs.gs_user_objects.imei = gs.gs_objects.imei
WHERE dispatch.tablet_dispatch.client_id = '299' ");
?>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><a href="#!"><? echo $rows['name']; ?></a></td>
<td><? echo $rows['d_name']; ?></td>
<td><? echo $rows['destination']; ?></td>
<td><? echo $rows['lat']; ?>, <? echo $rows['lng']; ?></td>
<td><? echo $rows['dt_server']; ?></td>
</tr>
<?php } ?>
The inner join works and it is getting the correct information. The problem I have is it is looping thru and sending multiple of the same information to the PHP table.
I Have a DB dispatch.tablet_dispatch.reg and the reg information in there is only one per vehicle so I want to join that table with information found in the other DB using the ID as specified '299' the id is common in all tables and linking with data from gs.gs_objects.name
Upvotes: 1
Views: 52
Reputation: 461
Try Group by in your query and it will be work. Ex. Group by id
Upvotes: 0