Reputation: 1295
Actually I was confused to give the title for this question. I have condition like this.
When we get record from database using limit
like select * from table_name limit 0,5
we get the data from 0 to 5 and when we use limit 5,10
we get 10 records from 5... Is it possible to display that particular index of the record using php.
Thanks..............
Upvotes: 1
Views: 192
Reputation: 95153
You're using LIMIT incorrectly. LIMIT is START, LENGTH. Do LIMIT 5, 5 and you will get 5 records, starting at 5 (5-9).
Cheers,
Eric
Edit: Please see the MySQL documentation on this, as well. It's certainly useful!
Another Edit: This question has been edited since I answered, so I'll answer again. It seems that you want to get the index of the row that you're returning, so here's a SQL statement to get that:
set @myStart = 5;
set @myLimit = 10;
set @i = @myStart - 1;
select id, @i:=@i+1 as myrow from mytable limit @myStart, @myLimit
Note: I took this solution from here.
Upvotes: 2
Reputation: 12900
If I'm reading your question correctly you are trying to display an index along with each record that's been retrieved from the database. I would do this using a counter in the loop I was using to display the records.
Before the loop set the counter to the offset, and then increment it as you go along. If this is just a matter of displaying a counter, it's really very easy. It would only be slightly more complicated to USE that index for later work, although not much.
Upvotes: 1