PHP/Mysql: read data field value from lookup tables (split array)

angelac

New Member
I have 1 Mysql database with 2 tables:DOCUMENTS ... - staffID .....STAFF - ID - NameThe DOCUMENTS table assigns each document to a single or multiple users from the STAFF table therefore the staffID in the DOCUMENTS table consists of a comma separated array of staff ID's for example (2, 14).I managed to split the array into individual values:
  • 2
  • 14
but rather than having the ID numbers I would like to have the actual names from the STAFF table - how can I achieve this. Any help would be greatly appreciated - please see my current code below.\[code\]$result = mysql_query("SELECT organizations.orgName, documents.docName, documents.docEntry, documents.staffID, staff.Name, staff.IDFROM documents INNER JOIN organizations ON (documents.IDorg = organizations.IDorg) INNER JOIN staff ON (documents.staffID = staff.ID)")or die(mysql_error()); while($row = mysql_fetch_array($result)){ $splitA = $row['staffID']; $resultName = explode(',', $splitA ); $i=0; for($i=0;$i<count($resultName);$i++) { echo "<a href='http://stackoverflow.com/questions/3690113/staffview.php?ID=".$row['docName']. "'>". $resultName[$i]."</a><br>"; } echo '<hr>';}\[/code\]
 
Back
Top