Hi,
I'm currently making a ShoutBox script, which will be quite simple. However, for a paged listing, as far as I know, I would have to run two queries.
One of them, would have to check the number of rows, to know the limit calculus end.
Eg.
This has to run after a query, and this means that I would have to run two queries?
So, my idea -- Which I hope you have feeback on, is this:
I run a query, where I retrieve all rows.
This query I put in a session array, as then I can simply do a count() on the array and easilly generate a paged listing.
This will also give less stress on the database, as it wont have to run a new query with a new limit for each time.
Ps. I know that mysql will "buffer" a bit, but even so, I think the session will give less system stress?
Ps. It's a small page, and I guess noone will "never" bother to check the other pages in the shoutbox..
(shoutbox / guestbook).
My idea, is:
* Retrieve all rows, put in session array
* Generate paged listing, based on count($session_array) and divided on $perpage.
I would have to have some way to "refresh" the session array.
Is this a "dumb" idea, should I just as well run two queries? In my silly mind, I think it would be better to store the results in a session and then maybe set expires after some minutes, if on first page of listing.
Olav Alexander Mjelde
Admin & Webmaster
I'm currently making a ShoutBox script, which will be quite simple. However, for a paged listing, as far as I know, I would have to run two queries.
One of them, would have to check the number of rows, to know the limit calculus end.
Eg.
Code:
$numrows = mysql_num_rows($get_main);
// how many pages we have when using paging?
$maxPage = ceil($numrows/$limitposts);
This has to run after a query, and this means that I would have to run two queries?
So, my idea -- Which I hope you have feeback on, is this:
I run a query, where I retrieve all rows.
This query I put in a session array, as then I can simply do a count() on the array and easilly generate a paged listing.
This will also give less stress on the database, as it wont have to run a new query with a new limit for each time.
Ps. I know that mysql will "buffer" a bit, but even so, I think the session will give less system stress?
Ps. It's a small page, and I guess noone will "never" bother to check the other pages in the shoutbox..
(shoutbox / guestbook).
My idea, is:
* Retrieve all rows, put in session array
* Generate paged listing, based on count($session_array) and divided on $perpage.
I would have to have some way to "refresh" the session array.
Is this a "dumb" idea, should I just as well run two queries? In my silly mind, I think it would be better to store the results in a session and then maybe set expires after some minutes, if on first page of listing.
Olav Alexander Mjelde
Admin & Webmaster