Maybe I could have formatted this better but this should work in terms of the concept you are looking for.
Loop over email result set.
<tr class="email_unread"><td><img class="email" id="email_id_'.$email_id.'" /></td><td> '.$email_subject.' </td></tr>
You would set the class to either email_read or email_unread depending on whether or not the email has been read. if($email_read = 1) $css = "email_read"; else $css = "email_unread";
Use jQuery to do the Dirty Work.
<script type="text/javascript">
$(document).ready(function() {
$("img.email").click(function(){
$.get("emailRead.php", { id: $(this).attr("id") } );
$(this).parent().parent().removeClass('email_unread').addClass('email_read');
});
});
</script>
This would be emailRead.php
connect_db(); // CONNECT TO DB
$id = $_GET['id'];
$id = str_replace("email_id_","",$id);
$query="UPDATE email SET email_read = 1 WHERE email_id = '$id'";
$getResults=mysql_query($query) or die(mysql_error());
Here you grab the GET var, trim the email_id_ part to just get the number and then use it in the update query. Of course you would have to do Security checks on what is coming into emailRead.php