I need help. I am trying to grab the timestamp for the last reply to a ticket. IN this example it would belong to parent id number 16 and there are three entries (rows) so I need to grab the last reply so I can make a last reply date and time for the ticket reply.
I am trying to attach a screenshot but still is not working.
This may look confusing, so to clarify I merged together two posts. Each one had a link at the top and bottom, so there may be confusion between the two.
Anyways, you can use the MAX aggregate on this.
Code:
SELECT parent, MAX(`timestamp`) FROM table GROUP BY parent
You can add a WHERE clause for the parent if you have a specific id to work with as well.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
I need to get the timestamp for the last reply to a ticket from the parent id number. In this example would be the parent id number 16.
This gives you what you want, right ?
Code:
SELECT MAX(`timestamp`) FROM replies WHERE type = 'ticket' and parent = "16"
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Users who have thanked BubikolRamios for this post:
I doubt anyone but you have any idea is that now correct or not ?
(-:
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Users who have thanked BubikolRamios for this post:
I should clarify. the original ticket is in another table called tickets. The replies are in a table called replies such as shown above. I need to show the last reply date to a response to the ticket which is in the timestamp column under the replies table also shown in the screenshot shown in first post.
SELECT MAX(`timestamp`) FROM replies WHERE type = 'ticket' and parent = "16"
this can no way return 'resource id22'
Then go to PHP part.
BTW - one of links to images in upper posts is broken.
__________________
Found a flower or bug and don't know what it is ? agrozoo.net galery
if you don't spot search button at once, there is search form: agrozoo.net galery search
Last edited by BubikolRamios; 02-27-2013 at 03:09 PM..
Users who have thanked BubikolRamios for this post:
The resource id means you are doing something wrong in PHP. It has nothing to do with MySQL. In fact, the fact that you are getting a resource id other than zero means that the query *IS* working (at least in the sense it is doing *something*).
If you won't show your PHP code, nobody can help you.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
I do have mysql client as all other info is populated perfectly as normal. I just decided to add the last reply field and for some reason just cannot for the life of me get it to work