Help - Search - Member List - Calendar
Full Version: top 3 query, how?
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
Jim S.
hi guys,
I have a table that am calculating number of clicks in it, how can i make a
query that will give me the top 3 (or what ever number, 4, or 5 ...) my
brain at this moment 4:00 AM does not seem to want to help me out, so please
help.
thanks
Jim

if u feel like it, maybe u can help with the next question (am doing a
different post for it too)
i did this before, but i forgot what i used,
anyhow, i have a field that maybe 255 characters, i want to display only
100, how can i do that?
thanks again
Jim

Stefan Rybacki
Jim S. wrote:
QUOTE
hi guys,
I have a table that am calculating number of clicks in it, how can i make a
query that will give me the top 3 (or what ever number, 4, or 5 ...) my
brain at this moment 4:00 AM does not seem to want to help me out, so please
help.
thanks
Jim

Which RDBMS are you using?

mySQL knows LIMIT

SELECT clicks FROM clicktable ORDER BY clicks DESC LIMIT 1,3


SQLServer for example has the TOP keyword

SELECT TOP 3 clicks FROM clicktable ORDER BY clicks DESC


QUOTE

if u feel like it, maybe u can help with the next question (am doing a
different post for it too)
i did this before, but i forgot what i used,
anyhow, i have a field that maybe 255 characters, i want to display only
100, how can i do that?
thanks again
Jim

Do you want a SQL solution or a PHP one?

SQL: have a look at aggregat functions for Strings like SUBSTRING
$text100=PHP substr($text,0,100);


Regards
Stefan
QUOTE



Oli Filth
Stefan Rybacki said the following on 27/06/2005 10:56:
QUOTE
Jim S. wrote:

hi guys,
I have a table that am calculating number of clicks in it, how can i
make a
query that will give me the top 3 (or what ever number, 4, or 5 ...) my
brain at this moment 4:00 AM does not seem to want to help me out, so
please
help.
thanks
Jim


Which RDBMS are you using?

mySQL knows LIMIT

SELECT clicks FROM clicktable ORDER BY clicks DESC LIMIT 1,3


That should be:

LIMIT 0, 3

or:

LIMIT 3

Row-numbering starts from 0.


--
Oli

Stefan Rybacki
Oli Filth wrote:
QUOTE
Stefan Rybacki said the following on 27/06/2005 10:56:

Jim S. wrote:

hi guys,
I have a table that am calculating number of clicks in it, how can i
make a
query that will give me the top 3 (or what ever number, 4, or 5 ...) my
brain at this moment 4:00 AM does not seem to want to help me out, so
please
help.
thanks
Jim



Which RDBMS are you using?

mySQL knows LIMIT

SELECT clicks FROM clicktable ORDER BY clicks DESC LIMIT 1,3


That should be:

LIMIT 0, 3

or:

LIMIT 3

Row-numbering starts from 0.


Yes of course, sorry.

Jim S.
thank u very much guys, that was super.

note: am using php and mysql


"Jim S." <[Email Removed]> wrote in message
news:QBOve.12809$[Email Removed]...
QUOTE
hi guys,
I have a table that am calculating number of clicks in it, how can i make
a
query that will give me the top 3 (or what ever number, 4, or 5 ...) my
brain at this moment 4:00 AM does not seem to want to help me out, so
please
help.
thanks
Jim

if u feel like it, maybe u can help with the next question (am doing a
different post for it too)
i did this before, but i forgot what i used,
anyhow, i have a field that maybe 255 characters, i want to display only
100, how can i do that?
thanks again
Jim




PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.