Get the highest result from a msql_query using php?

This is a discussion on Get the highest result from a msql_query using php? within the PHP Language forums, part of the PHP Programming Forums category; I have a result resource from a large mysql query and I need to find the single the highest value ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-01-2007
Ciaran
 
Posts: n/a
Default Get the highest result from a msql_query using php?

I have a result resource from a large mysql query and I need to find
the single the highest value from a certain field. What's the best way
to pull it off?
Cheers,
Ciarán
Reply With Quote
  #2 (permalink)  
Old 12-01-2007
Shelly
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?

Ciaran wrote:
> I have a result resource from a large mysql query and I need to find
> the single the highest value from a certain field. What's the best way
> to pull it off?
> Cheers,
> Ciarán


A simple google of "sql max" would have led you to:
SELECT MAX(expression )
FROM tables
WHERE predicates;

--

Shelly


Reply With Quote
  #3 (permalink)  
Old 12-01-2007
Ciaran
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?

On Dec 1, 10:43 am, "Shelly" <sheldonlg.n...@asap-consult.com> wrote:
> Ciaran wrote:
> > I have a result resource from a large mysql query and I need to find
> > the single the highest value from a certain field. What's the best way
> > to pull it off?
> > Cheers,
> > Ciarán

>
> A simple google of "sql max" would have led you to:
> SELECT MAX(expression )
> FROM tables
> WHERE predicates;
>
> --
>
> Shelly


Thanks Shelly but I'm not great with sql and my query is already huge.
I don't think I'll be able to modify it to include the max as well as
everything else. Not to worry - I'm going to split the results into a
3d array and then try to sort it with php.
Thanks for the help
Reply With Quote
  #4 (permalink)  
Old 12-01-2007
Jonas Werres
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?

> Thanks Shelly but I'm not great with sql and my query is already huge.
> I don't think I'll be able to modify it to include the max as well as
> everything else. Not to worry - I'm going to split the results into a
> 3d array and then try to sort it with php.
> Thanks for the help


So, you go to the library, take all the books, reorganise them, search
for the one you want to read and return the rest?
Reply With Quote
  #5 (permalink)  
Old 12-01-2007
Animesh K
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?

Jonas Werres wrote:
>> Thanks Shelly but I'm not great with sql and my query is already huge.
>> I don't think I'll be able to modify it to include the max as well as
>> everything else. Not to worry - I'm going to split the results into a
>> 3d array and then try to sort it with php.
>> Thanks for the help

>
> So, you go to the library, take all the books, reorganise them, search
> for the one you want to read and return the rest?


Nice comparison there.
Reply With Quote
  #6 (permalink)  
Old 12-02-2007
Richard
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?


"Jonas Werres" <jonas@example.org> wrote in message
news:47519002$0$13116$9b4e6d93@newsspool2.arcor-online.net...
>> Thanks Shelly but I'm not great with sql and my query is already huge.
>> I don't think I'll be able to modify it to include the max as well as
>> everything else. Not to worry - I'm going to split the results into a
>> 3d array and then try to sort it with php.
>> Thanks for the help

>
> So, you go to the library, take all the books, reorganise them, search for
> the one you want to read and return the rest?


No, you throw the rest away! ;)

R.


Reply With Quote
  #7 (permalink)  
Old 12-02-2007
Ciaran
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?

Actually, I'm using all returned records further down my page - I just
want to pull the newest one to reference at the top.
Not to worry - the php is working out better for my design and I
almost have it sorted now anyway.
Cheers,
Ciarán
Reply With Quote
  #8 (permalink)  
Old 12-02-2007
Jonas Werres
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?

> Not to worry - the php is working out better for my design and I
> almost have it sorted now anyway.

And I am almost sure, that even a second query would work out better.
Reply With Quote
  #9 (permalink)  
Old 12-03-2007
AnrDaemon
 
Posts: n/a
Default Re: Get the highest result from a msql_query using php?

Greetings, Ciaran.
In reply to Your message dated Sunday, December 2, 2007, 06:10:34,

> Actually, I'm using all returned records further down my page - I just
> want to pull the newest one to reference at the top.
> Not to worry - the php is working out better for my design and I
> almost have it sorted now anyway.


Why You aren't using SQL ORDER BY clause then?
Using it properly You'll be always sure that Your newest entry is always on
the top of query result.


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:48 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0