Click to See Complete Forum and Search --> : Getting first reply


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! :)

DanUK
11-03-2009, 10:45 PM
Can anyone please spare a few moments to help me out? I'm having a nightmare with this query :(

Thanks!

ssystems
11-03-2009, 11:04 PM
Did you try to reverse the order and get the first item?


ORDER BY r.dateadded Limit 0,1

DanUK
11-04-2009, 10:24 AM
Thanks for your reply ssystems.

Unfortunately still the same! :(