MySQL: display page containing record -
Assume the following records:
id value ========= 1. No 2. No 3. Not 4. No 5. No 6. No 7. Yes 8. No 9. No. 10. No Every "page" of my records - Display 5 records are included (hence the page 1 has a 1-5 record, page 2 has 6-10 records, and so on ...). I want to display the page that is recorded with the value of yes . Keep in mind that I do not know that this is in the yes record. How do I ask this?
about something like this:
/ * page Work out from * / SELECT @ MATCHID = id from tbl where value = 'yes' id to ASC limit 1; SELECT @ Page = CEIL (COUNT (*) / 5) From TBL to ID & lt; = @MatchID; / * Select the item on that page * / SET @offset = (@Page-1) * 5; SELECT * FROM tbl ORDER by IDSc border @ offset, 5; Note: The above mentioned @ ID is not completed for the ID.
I am unsure whether the range of MySQL is stable, so if they do you have to calculate the offset in PHP, or whatever programming language you are using to connect to MySQL optional In the form, it will probably work in the above example, instead of the final selection statement:
SET @selectSQL = CONCAT ('SELECT * FROM tbl ORDER by ID ASC Ltd', @ offset, ', 5 '); Prepare stmt from @selectSQL; EXTUTE STMT;
Comments
Post a Comment