Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2013, 11:06 PM   PM User | #1
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point


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.

I posted an image screenshot but it's not showing so here it is.

http://www.flickr.com/photos/93602215@N06/8510774240/



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.

Mysql screenshot
fondy98 is offline   Reply With Quote
Old 02-26-2013, 11:11 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,647
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 02:18 AM   PM User | #3
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
The output shows:

Resource id #45

Which is not correct.

I used:

"SELECT parent, MAX(`timestamp`) FROM " . PREFIX . "replies GROUP BY parent"
fondy98 is offline   Reply With Quote
Old 02-27-2013, 02:21 AM   PM User | #4
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
I also tried this:

"SELECT parent, MAX(`timestamp`) FROM " . PREFIX . "replies WHERE type = 'ticket' GROUP BY parent"
fondy98 is offline   Reply With Quote
Old 02-27-2013, 05:30 AM   PM User | #5
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
Sorry, I am still having no luck at all.
fondy98 is offline   Reply With Quote
Old 02-27-2013, 07:49 AM   PM User | #6
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
Quote:
Originally Posted by fondy98 View Post

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
BubikolRamios is offline   Reply With Quote
Users who have thanked BubikolRamios for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 12:49 PM   PM User | #7
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
I tried SELECT MAX(`timestamp`) FROM replies WHERE type = 'ticket' and parent = "16"

and

"SELECT MAX(`timestamp`) FROM " . PREFIX . "replies WHERE type = 'ticket' and parent = '16'"

and now it shows Resource id #22
fondy98 is offline   Reply With Quote
Old 02-27-2013, 12:57 PM   PM User | #8
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
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
BubikolRamios is offline   Reply With Quote
Users who have thanked BubikolRamios for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 12:59 PM   PM User | #9
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
No. It should show the timestamp number. But for some reason it is showing the resource id22
fondy98 is offline   Reply With Quote
Old 02-27-2013, 01:13 PM   PM User | #10
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
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.

Here is a screenshot of what it looks like
http://www.flickr.com/photos/93602215@N06/8513212140/

Last edited by fondy98; 02-27-2013 at 01:31 PM.. Reason: error
fondy98 is offline   Reply With Quote
Old 02-27-2013, 03:05 PM   PM User | #11
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
Quote:
But for some reason it is showing the resource id22
Who, where ?

You are 'mixing' here PHP and MYSQL, while you are not sure that mysql part is OK jet.

First clarify what is going on at mysql part. Separately !

My filling is you dont have a mysql client.
Get this: http://www.heidisql.com/download.php

Check what that sql client returns on:
Code:
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..
BubikolRamios is offline   Reply With Quote
Users who have thanked BubikolRamios for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 03:56 PM   PM User | #12
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 03:57 PM   PM User | #13
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Bubikol: He must have a mysql client else where would he be getting the resource id number from?

I think he just doesn't know how to USE the mysql client.
__________________
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 05:04 PM   PM User | #14
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
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
fondy98 is offline   Reply With Quote
Old 02-27-2013, 05:19 PM   PM User | #15
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
When I run the query right in phpmyadmin/mysql, it now returns the timestamp. But now I cannot get it to work in the script.

$replied = $site->db->query("SELECT MAX(`timestamp`) FROM support_replies WHERE type = 'ticket' and parent = '16'");

In the line above, we use ( $site->db-> ) for all queries and such.
fondy98 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:04 PM.


Advertisement
Log in to turn off these ads.