Break up query into pages using PHP from MsSQL
| From: | Dean Householder | Date: | Thu, 28 Mar 2002 07:47:58 +0000 |
| Subject: | Break up query into pages using PHP from MsSQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-90489@lists.php.net to get a copy of this message | ||
I'm trying to split results into different pages and number the pages
accordingly. I'm using PHP and accessing a MsSQL database. I've been able to
build a fairly intelligent page numbering system which knows which rows it
should pull (at least by numbering each row numerically) but I don't know
how to construct a SQL query to pull 10 results starting at a certain
number. I know MySQL has a function called offset. This combined with the
limit function would be great! But MsSQL doesn't seem to work in the same
way. Here's what I have so far:
SELECT count(id) FROM members WHERE bla bla bla
then load that into a variable called $total.
SELECT TOP 10 * FROM members WHERE bla bla bla
TOP is the function to only pull a certain number of records. (I had to
figure that out the hard way!) I was thinking of possibly making the WHERE
statement like
WHERE id >= $start AND id <= $start + 10
But that only works if my indexes are consistant. Which they aren't! As I
see it, I either need to reindex the table, find a function in MsSQL that
works, or pull everything into a big PHP array and try to sort it out there.
Any hints or suggestions would be greatly appreciated!!!
Thanks,
Dean