How to print the last name only, whenever it is unique? Else print the full name as 'last name, first name'.
Example: In the database, you have: Ace Perez, Dan Perez, James Perez and Dan Bond. It should display something like:
Perez Ace Perez Dan Perez James Bond
It will only display Bond instead of Bond Dan, since it's a unique last name.
Here is my code snippet:
<?php
$display = "SELECT * FROM main ORDER BY lastName ASC, firstName ASC";
$result = @mysql_query($display)or die(mysql_error());
while($row = mysql_fetch_array($result)){
$lastName = $row['lastName'];
$firstName = $row['firstName'];
$score = $row['score'];
$totalScore = $row['totalScore'];
$percentage = ($score/$totalScore)*100;
echo "<tr>";
echo "<td align='left'> $lastName </td>";
echo "<td align='left'> $firstName </td>";
echo "<td align='left'> $percentage </td>";
echo "</tr>";
}
echo "</table>";
?>
Edit: Sorry, I'm quite new here. The snippet should be displaying properly now! :)