Hi all,
I am working on an application which is retrieving data from a table in the database, and the data is then updated using an SQL statement. However, it seems that the PHP code which updates the data is being ran before the data is retrieved.
Can anyone suggust how to solve this problem?
<?php $supervisorId = getSupervisorId($email,$conn);
$sql="SELECT * FROM tblsupervisornotification WHERE supervisorId=" . $supervisorId ." AND viewed=0";
$result = mysql_query($sql);
$num=mysql_num_rows($result);
if ($num==0)
{
?>
<div id="content">There are no new notifications to view</div>
<?php
}
else if ($num>0)
{
?>
<div id="content">
<table>
<?php
$row = mysql_fetch_assoc($result);
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result))
{
$id=$row['supervisorId'];
$message = $row['message'];
?>
<tr>
<td><?php echo $message; ?></td>
</tr>
<?php
}
echo "nooo!";
$sql="UPDATE tblsupervisornotification set viewed=1 WHERE supervisorId='". $supervisorId . "' AND viewed=0";
$result = mysql_query($sql);
?>
</table>
</div>
Many thanks,