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

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 03-20-2007, 07:01 PM   PM User | #1
mwm
Regular Coder

 
Join Date: Oct 2005
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
mwm has a little shameless behaviour in the past
how to get next date?

I have a contact form that inserts the date the last time a sales person has made contact with the buyer. I want to display this in a report, so when they run the report it show the last date contact was made. something like select next closes date to current date. any ideas how this could be done?

Thanks
mwm is offline   Reply With Quote
Old 03-20-2007, 08:52 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
SELECT MAX(contactDate) FROM contactTable where buyer = $buyer will select the highest (most current) date. Is that what you're after?
__________________
Fumigator is offline   Reply With Quote
Old 03-20-2007, 10:09 PM   PM User | #3
mwm
Regular Coder

 
Join Date: Oct 2005
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
mwm has a little shameless behaviour in the past
Yes that's what I was going for, but still can't make it work. Here is the query

PHP Code:
$mysql = ("select cust.id,cust.fname,cust.lname,cust.address,cust.city,cust.state,cust.zip,cust.hphone,cust.community,date_format(cust.regdate, '%m-%d-%Y'), sum(followup.tpcount) as t_count, MAX(followup.tpdate) from cust, followup where cust.regdate < curdate() - interval 0 day and community = '$community' and cust.id = followup.id and status = 'Prospect'  group by lname having t_count < 1"); 
mwm is offline   Reply With Quote
Old 03-20-2007, 10:54 PM   PM User | #4
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
SUM() and MAX() are column functions so they can't be mixed with non-column functions... basically when you do a "GROUP BY" you you can only select columns that are in that GROUP BY clause.

A way around this is to do a subquery, but your version of MySQL must be 4.1 or greater.

Code:
SELECT *
FROM table1 as a
WHERE date1 = (select MAX(date1) from table1 as b WHERE a.id = b.id)
__________________
Fumigator 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 12:21 PM.


Advertisement
Log in to turn off these ads.