Duplicate information from sql result

Posted by puddleJumper on Stack Overflow See other posts from Stack Overflow or by puddleJumper
Published on 2012-10-06T23:55:29Z Indexed on 2012/10/08 3:37 UTC
Read the original article Hit count: 127

Filed under:
|
|

I looked in about 18 other posts on here an most people are asking how to delete the records not just hide them. So my problem: I have a database with staff members who are associated with locations. Many of the staff members are associated with more than one location. What I want to do is to only display the first location listed in the mysql result and skip over the others. I have the sql query linking the tables together and it works aside from it showing the same information for those staff members that are in those other locations multiple times so example would be like this:

enter image description here

This is the sql statement I have currently

    SELECT staff_tbl.staffID, staff_tbl.firstName, staff_tbl.middleInitial, staff_tbl.lastName,
     location_tbl.locationID, location_tbl.staffID, 
    officelocations_tbl.locationID, officelocations_tbl.officeName, staff_title_tbl.title_ID,
     staff_title_tbl.staff_ID, titles_tbl.titleID, titles_tbl.titleName

    FROM staff_tbl 

    INNER JOIN location_tbl ON location_tbl.staffID = staff_tbl.staffID 
    INNER JOIN officelocations_tbl ON location_tbl.locationID = officelocations_tbl.locationID
    INNER JOIN staff_title_tbl ON staff_title_tbl.staff_ID = staff_tbl.staffID 
    INNER JOIN titles_tbl ON staff_title_tbl.title_ID = titles_tbl.titleID 

and my php is

      <?php do { ?>
<tr>
  <td><?php echo $row_rs_Staff_Info['firstName']; ?>&nbsp; <?php echo $row_rs_Staff_Info['lastName']; ?></td>
  <td><?php echo $row_rs_Staff_Info['titleName']; ?>&nbsp; </td>
  <td><?php echo $row_rs_Staff_Info['officeName']; ?>&nbsp; </td>

</tr>
<?php } while ($row_mysqlResult = mysql_fetch_assoc($rs_mysqlResult)); ?>

What I would like to know is there a way using php to select only the first entry listed for each person and display that and just skip over the other two. I was thinking it could be done by possibly adding the staffID's to an array and if they are in there to skip over the next one listed in the staff_title_tbl but wasn't quite sure how to write it that way. Any help would be great thank you in advance.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql