DanUK
11-01-2009, 07:39 PM
Hi guys, I hope you can help me out please.
I am using these queries (replacing a really ugly method in PHP) to find out whether the *first reply* in a 'supportreply' table linking to a 'support' table of tickets were under 24 hours.
Using this method I think it's going through every reply, and not just the first one which is causing incorrect reporting. Can anyone help me with getting it to just find the first reply for a ticket id?
$sql = "SELECT COUNT(*) AS `over` FROM supportreply r, support t WHERE user=1 AND r.id_ticket=t.id_ticket AND r.dateadded > t.dateadded AND TIMESTAMPDIFF(SECOND, r.dateadded, t.dateadded)>86400 ORDER BY r.dateadded";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$over_support = $row['over'];
$sql = "SELECT COUNT(*) AS `under` FROM supportreply r, support t WHERE user=1 AND r.id_ticket=t.id_ticket AND r.dateadded > t.dateadded AND TIMESTAMPDIFF(SECOND, r.dateadded, t.dateadded)<=86400 ORDER BY r.dateadded";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$under_support = $row['under'];
I have also tried adding "LIMIT 1" to it, to no avail.
I hope this makes sense, and thanks! :)
I am using these queries (replacing a really ugly method in PHP) to find out whether the *first reply* in a 'supportreply' table linking to a 'support' table of tickets were under 24 hours.
Using this method I think it's going through every reply, and not just the first one which is causing incorrect reporting. Can anyone help me with getting it to just find the first reply for a ticket id?
$sql = "SELECT COUNT(*) AS `over` FROM supportreply r, support t WHERE user=1 AND r.id_ticket=t.id_ticket AND r.dateadded > t.dateadded AND TIMESTAMPDIFF(SECOND, r.dateadded, t.dateadded)>86400 ORDER BY r.dateadded";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$over_support = $row['over'];
$sql = "SELECT COUNT(*) AS `under` FROM supportreply r, support t WHERE user=1 AND r.id_ticket=t.id_ticket AND r.dateadded > t.dateadded AND TIMESTAMPDIFF(SECOND, r.dateadded, t.dateadded)<=86400 ORDER BY r.dateadded";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$under_support = $row['under'];
I have also tried adding "LIMIT 1" to it, to no avail.
I hope this makes sense, and thanks! :)