[PHP] Complex(ish) Question for Newbie

2002-05-18 Thread webmaster



How can I return the last five lines of a mySQL 
database table?

JJ Harrison[EMAIL PROTECTED]www.tececo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Complex(ish) Question for Newbie

2002-05-18 Thread The_RadiX

Goody another easy to answer one :) no harm intended.. it's a perfectly good question


Okay first is it sorted how you want?

if so you can use the LIMIT start,len feature of mysql..


for example:

select * from table_name order by col_name limit 5,10

will select records 5 to 15 (5+10) if of course there are 10 more to collect otherwise 
it will just return whatever it finds from the select that is ordered by col_name..


quite simple..


:::
:  Julien Bonastre [The-Spectrum.org CEO]
:  A.K.A. The_RadiX
:  [EMAIL PROTECTED]
:  ABN: 64 235 749 494
:  QUT Student #: 04475739
:::
  - Original Message - 
  From: [EMAIL PROTECTED] 
  To: [EMAIL PROTECTED] 
  Sent: Sunday, May 19, 2002 12:01 AM
  Subject: [PHP] Complex(ish) Question for Newbie


  How can I return the last five lines of a mySQL database table?

  JJ Harrison
  [EMAIL PROTECTED]
  www.tececo.com


--


  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Complex(ish) Question for Newbie

2002-05-18 Thread The_RadiX

well personally I have never had a good time with mysql_num_rows.. dunno why.. never 
seemed to have worked the way it should for me..


anyway point is if it works for you good, otherwise do what I do to get a rowcount and 
just:
$sql_count=mysql_fetch_array(mysql_query(SELECT count(*) FROM table_name,$DB));


and then you can just refer to it via $sql_count[0]...


anyways after that it depends.. what do you want to do?


if for example you want a page listing system in which you have say 1000 records and 
you want to display only 30 per page or something and users can browse through by 
hitting prev page and next page etc.. that's easy to do...



just be more specific on what you want to do..






:::
:  Julien Bonastre [The-Spectrum.org CEO]
:  A.K.A. The_RadiX
:  [EMAIL PROTECTED]
:  ABN: 64 235 749 494
:  QUT Student #: 04475739
:::
- Original Message - 
From: [EMAIL PROTECTED]
To: The_RadiX [EMAIL PROTECTED]
Sent: Sunday, May 19, 2002 12:39 AM
Subject: Re: [PHP] Complex(ish) Question for Newbie


 Thanks.
 
 What is the best way to make the limit update it self as I add more entires.
 
 I am thinking of using a blank query (SELECT code FROM links)
 and then counting the number of rows with mysql_num_rows().
 
 But wouldn't this be a little slow if the database was big?
 
 - Original Message -
 From: The_RadiX [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Sunday, May 19, 2002 12:07 AM
 Subject: Re: [PHP] Complex(ish) Question for Newbie
 
 
 Goody another easy to answer one :) no harm intended.. it's a perfectly good
 question
 
 
 Okay first is it sorted how you want?
 
 if so you can use the LIMIT start,len feature of mysql..
 
 
 for example:
 
 select * from table_name order by col_name limit 5,10
 
 will select records 5 to 15 (5+10) if of course there are 10 more to collect
 otherwise it will just return whatever it finds from the select that is
 ordered by col_name..
 
 
 quite simple..
 
 
 :::
 :  Julien Bonastre [The-Spectrum.org CEO]
 :  A.K.A. The_RadiX
 :  [EMAIL PROTECTED]
 :  ABN: 64 235 749 494
 :  QUT Student #: 04475739
 :::
   - Original Message -
   From: [EMAIL PROTECTED]
   To: [EMAIL PROTECTED]
   Sent: Sunday, May 19, 2002 12:01 AM
   Subject: [PHP] Complex(ish) Question for Newbie
 
 
   How can I return the last five lines of a mySQL database table?
 
   JJ Harrison
   [EMAIL PROTECTED]
   www.tececo.com
 
 
 
 --
 
 
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php