PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old September 7th, 2004, 07:23 AM
Black Black is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 Black User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Getting the max values records

Hi all, do help me...
I have a table with these fields...

id | line | header | description
= | === | ===== | =========
1 | hi | good |how are you?
2 |U | wow |how is your class?
3 |me |trouble |problem with fetching records

etc....

the id is auto incremented as and when the records are inserted. Now the problem is once, I want to fetch the record, then the id with the maximum number should be displayed. the query works fine if it is with individual statements like

select max(ad_id) as Idd from pbl_content or

select ad_id, ad_top_line, ad_header, ad_description from pbl_content.

I want to get the value of the id with the max value and once I write the coding the error coming is

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

and my query is
select ad_top_line, ad_header, ad_description from pbl_content where ad_id=max(ad_id)

Last edited by Black : September 7th, 2004 at 07:26 AM. Reason: alignment

Reply With Quote
  #2  
Old September 7th, 2004, 07:44 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
If you order the results by id descending and limit the results to 1 this should achieve that effect. Something like (this is bound to be a bit off as I have no way of testing it) -

SELECT ad_top_line, ad_header, ad_description from pbl_content ORDER BY ad_id DESC LIMIT 1

Hope this helps,

-KM-

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Getting the max values records


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway