You have two problems. The first is that you write:
if($ticketstatus = "open")
which is probably incorrect since it assigns "open" to $ticketstatus instead of comparing them. This then done again when you write:
else{ if($ticketstatus = "closed")
The next problem is with the code logic, which says:
if $difference < 5, do x
if $difference >= 5, do y
if $difference >= 10, do z
But if $difference is greater than or equal to 10, it is also greater than or equal to 5, so both y and z are done.
To correct these problems:
<?php
$ticketstatus = $row['status'];
$begin = strtotime($row['startdate']);
$now = time();
$subdiff = $now - $begin;
$difference = round($subdiff /60 /60 /24);
$style = '';
if ($ticketstatus == 'open') {
if ($difference < 5) {
$style = 'background:green;color:white';
} else if ($difference < 10) {
$style = 'background:yellow';
} else {
$style = 'background:red';
}
}
else {
$style = 'background:white;color:silver';
}
echo "<p style='$style'>" . htmlspecialchars(stripslashes($row['incidentno'])) . "</p>";
?>
Instead of using stripslashes(), I recommend changing php.ini to turn magic_quotes_gpc to Off. I added the [man]htmlspecialchars/man as a precaution to avoid malicious code injection.