Yes, the skip parameter can be thought of as the zero based index of the first row to retrieve. So, limit 2,7will return 7 rows starting from the 3rd row.
I would suggest you create a simple table like this create table test (val1 int); And insert dummy values into it as insert into test (val1) values (1),(2),(3),(4); And then play with the limit clause to get a proper feel of it. Alex Hall wrote:
So limit 2,7 would be records 2-8, or 3-9? If the index starts at 0 then it should start at the number you skipped, right?Have a great day, Alex----- Original Message ----- From: "Holdsworth, Lynn" <Lynn.Holdsworth@xxxxxxxxxxx To: <programmingblind@xxxxxxxxxxxxx Date sent: Wed, 8 Apr 2009 15:09:59 +0100 Subject: RE: quick mysql questionHi Alex,Remember that the skip argument has a zero index, so Niran'sexamplewould actually skip 10 records and bring back from the 11th rowonwards.Cheers, Lynn-----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of niran Sent: 09 April 2009 03:10 To: programmingblind@xxxxxxxxxxxxx Subject: Re: quick mysql questionThe syntax of limit clause is select .... limit skip , sizeThe limit clause will skip specified number of rows from theresult andreturn the rows specified in size. For example select * fromusers limit10 , 10; will return 10 users starting from 10th user in theresult set.Alex Hall wrote:That makes a lot of sense. I have heard of limit 20, which willselect the first 20 rows, but what is the comma? I guess Ishould say:what is the syntax of the limit clause? Thanks!Have a great day, Alex----- Original Message ----- From: "Holdsworth, Lynn" <Lynn.Holdsworth@xxxxxxxxxxx To: <programmingblind@xxxxxxxxxxxxx Date sent: Wed, 8 Apr 2009 13:04:14 +0100 Subject: RE: quick mysql questionHi Alex,I don't think you need row numbers to accomplish paging.I've written some PHP code below, which you'll need to tweak abit.If you can put the page number in the querystring:-http://www.something.com/somepage.php?page=3Then you can tweak the SQL statement with a limit clause:-<?php .... Extract($_GET); //exposes variables from the querystring $recordsPerPage = 5; //Number of records on each page//If page number not set, then set it to 1 If (!$page) { $page =1; }//Calculate the first record you want to retrieve on this page//Index is zero-based $firstRecord = $recordsPerPage *($page-1);//Now build the SQL query with the limit clause $query = "select<fieldNames From <tableName Where <whereClause Limit$firstRecord,$recordsPerPage"; .... ?Let us know if this works for you.Cheers, LynnLynn Holdsworth Web Analyst/Programmer - www.rnib.org.uk-----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of AlexHallSent: 08 April 2009 12:47 To: programmingblind@xxxxxxxxxxxxx Subject: Re: quick mysql questionOkay. How would I use this to control which records aredisplayed? SayI have records 1-8, and the php page displays the first two,thenthenext two, and so on, moving to the next two every time a "next"buttonis clicked. How would the page know which two (or however manyit wasset to display per page) to get? What if the user wants to goback? Doesthis make sense? Sorry if this comes out looking strange, I think my bn's uebtranslatoris going crazy.Have a great day, Alex----- Original Message ----- From: "Octavian Rasnita" <orasnita@xxxxxxxxx To: <programmingblind@xxxxxxxxxxxxx Date sent: Wed, 8 Apr 2009 08:28:16 +0300 Subject: Re: quick mysql questionThe indexes in a table are used for creating relations with therecords fromother tables, and it would be a total mess if those indexeswouldchange.If you need to find how many records there are in a table, youcan simplycount them using:select count(*) from table_name;Or you can put some conditions like:select count(*) from table_name where column1=123 andanother_column="abc"and another_one like '%bla%';-- Octavian----- Original Message ----- From: "Alex Hall" <mehgcap@xxxxxxx To: <programmingblind@xxxxxxxxxxxxx Sent: Wednesday, April 08, 2009 6:21 AM Subject: Re: quick mysql questionOkay, so the numbering is lost if you delete. Is there a morerobust wayof numbering, so that you would have gotten: 1, abc' 2, 'ghi' 3, 'kno' instead? I need the index of each record to always be sequentialso that Ican know how many total records there are and also know whichones I haveused in the displaying of all of them.Have a great day, Alex----- Original Message ----- From: "R. Haynie" <rhaynie@xxxxxxxxxxx To: programmingblind@xxxxxxxxxxxxx Date sent: Tue, 07 Apr 2009 22:51:24 -0400 Subject: Re: quick mysql questionAn example is worth a thousand words...create table tbl1 (fld1 INTEGER AUTO_INCREMENT, fld2 char(3), PRIMARY KEY (fld1));insert into tbl1 (fld2) values ('abc'), ('def'), ('ghi'),('jkl');select * from tbl1; -- gives you: 1, 'abc' 2, 'def' 3, 'ghi' 4, 'jkl'delete from tbl1 where fld1 in (2, 4); insert into tbl1 (fld2) values ('mno'); select * from tbl1; -- gives you: 1, 'abc' 3, 'ghi' 5, 'mno'HTH. -RodneyAlex Hall wrote:Hi all, If I have a table of records and one column is an autoincrement,whathappens when I delete a record? I want to use the autoincrementas anindex, so records 1, 2, 3, and 4 exist where 1-4 are the indexesofthe records, If you delete record 3, do you then have records 1,2,and 3, or 1, 2, and 4? If it is the second case, is there abetter wayto have an index of each record? I need to know how manyrecordsI amusing on a page (it is sort of a photo viewer so I need to knowwhichpictures are being shown and how many more there are) and howmanytotal there are to go. Thanks.Have a great day, Alex __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind-- DISCLAIMER:NOTICE: The information contained in this email and anyattachments isconfidential and may be privileged. If you are not the intendedrecipient you should not use, disclose, distribute or copy anyofthecontent of it or of any attachment; you are requested to notifythesender immediately of your receipt of the email and then todelete itand any attachments from your system.RNIB endeavours to ensure that emails and any attachmentsgenerated byits staff are free from viruses or other contaminants. However,itcannot accept any responsibility for any such which aretransmitted.We therefore recommend you scan all attachments.Please note that the statements and views expressed in thisandany attachments are those of the author and do not necessarilyrepresentthose of RNIB.RNIB Registered Charity Number: 226227Website: http://www.rnib.org.ukThis message has been scanned for viruses by Websense HostedSecurity -http://www.websense.com/content/HostedEmailSecurity.aspx__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind