Jump to content


Mysql query question


9 replies to this topic

#1 Aussiestinger

    Young Padawan

  • Members
  • Pip
  • 270 posts

Posted 07 July 2006 - 03:38 PM

Is there any way to show the 15 newest except the very newest?

say i got

$query = "SELECT * FROM news ORDER BY ID DESC LIMIT 15";

is there anyway to make it show the latest 15 except the very latest? or it more complicated then that and would have to do with php?

#2 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 07 July 2006 - 03:53 PM

so, you want entries 15 - 30 (missing out the lastest 15) right?

try this:

$query = "SELECT * FROM `news` ORDER BY ID DESC LIMIT 15, 30";


#3 Erik Bernskiold

    Jedi In Training

  • Members
  • PipPip
  • 422 posts
  • Gender:Male
  • Location:Gothenburg, Sweden
  • Interests:I love to do booth Web Design and Photography. Nothing beats a nice day out in the nature with the camera gear, getting loads of nice photos. I have been playing the flute for 6 years now and I love it, and I am playing the pipe organ as well. I also like to teach other people the in and outs of software such as the CS3 suite from Adobe.

Posted 07 July 2006 - 03:54 PM

So you want to display item 2-15 and not number 1, is that correct?

#4 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 07 July 2006 - 03:56 PM

:o-->
QUOTE(Erik B @ Jul 7 2006, 09:53 PM) <{POST_SNAPBACK}>

So you want to display item 2-15 and not number 1, is that correct?
[/quote]

Could mean that also lol. People need to be more specific when posting :ph34r:



If that's the case.

#5 Erik Bernskiold

    Jedi In Training

  • Members
  • PipPip
  • 422 posts
  • Gender:Male
  • Location:Gothenburg, Sweden
  • Interests:I love to do booth Web Design and Photography. Nothing beats a nice day out in the nature with the camera gear, getting loads of nice photos. I have been playing the flute for 6 years now and I love it, and I am playing the pipe organ as well. I also like to teach other people the in and outs of software such as the CS3 suite from Adobe.

Posted 07 July 2006 - 04:03 PM

Often that is the case, and in case you havn't noticed, I really left this question to you since I am not too good with PHP...you would have known this by the top of your head, wheareas I would have been searching :ph34r:

Aussiestinger, hopefully that was what you wanted?

#6 Aussiestinger

    Young Padawan

  • Members
  • Pip
  • 270 posts

Posted 07 July 2006 - 04:38 PM

Yeah the second one is what I needed, thanks heaps works perfectly.

#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 08 July 2006 - 12:04 AM

View Post.Matt, on Jul 7 2006, 02:55 PM, said:

$query = "SELECT * FROM `news` ORDER BY ID DESC LIMIT 1, 16";
Souldn't that 16 be a 15? I'm asking because my long absence from actually coding might have made me forget something, but i believe the number after the comma is total results, and the number before is record to start at.

Just wanted to bring this up for future readers.

Edited by rc69, 08 July 2006 - 12:04 AM.


#8 liveman

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Location:New Jersey

Posted 08 July 2006 - 01:40 AM

Yeh, RC is right its 15, unless he still wants 15 shown except the first one?

#9 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 08 July 2006 - 02:21 AM

lol, i think doing nothing coding wise apart from help on forums for a few months is begining to show :$

Quote

unless he still wants 15 shown except the first one?

Thats how i read it, he says it works so it was probably right :) Good point though rc69.

#10 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 09 July 2006 - 12:08 AM

Thankfully my memory is good, so the decay will be slow at best. But either way, this will probably bug me till it's solved, and already knowing that, i decided to get MySQL's official opinion on the subject.

Since i read it the same way you two did, my way should be right.
[quote name='http://dev.mysql.com/doc/refman/4.1/en/select.html']The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements).

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15[/quote]

Either way, if it works how he wants it to, then it works, and there's nothing i'm willing to do to change that :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users