Q:

Distinguish duplicates in a foreach loop from sql

Hi so Im creating a job application management system. in the backend the admin needs to be able to see all those who have applied for a job and awaiting a response. here is my sql query:
'SELECT * FROM jp_applications WHERE application_status = "Awaiting Response" ORDER BY job_id'

my problem is that once i loop through and output this in a list of applicants I want to be able to add a class to that list element if it is a duplicate applicant. (one person applying for more than one job). 
ideally i want the list to be ordered by the job_id so i dont want to order it by say user_id.
I hope this makes sense.
<ul>
    <li class="duplicate">Joe Bloggs</li>
    <li>Michael Jackson</li>
    <li>Gandalf the Grey</li>
    <li>Mahatma Gandhi</li>
    <li class="duplicate">Joe Bloggs</li>
    <li>Daffy Duck</li>
    <li>Sponegbob Squarepants</li>
    <li>Will Smill</li>
</ul>

A:

Alternative - let the database do the work for you:
SELECT j.*, c.appl_count FROM jp_applications j
    INNER JOIN (SELECT user_id, count(1) as appl_count FROM jp_applications
            WHERE application_status = "Awaiting Response"
            GROUP BY user_id) c on c.user_id = j.user_id
WHERE j.application_status = "Awaiting Response"
ORDER BY j.job_id

Then your resultset will have the field 'appl_count' available, if greater than 1, append the class.  This removes the need to do any tit-for-tat accounting in the app code.

