You solution is quite resource expensive. I would do:
[find $maxpages]
SELECT COUNT(*)/12 FROM table WHERE id <= $real_id;
list($maxpages) = fetch_row()

In result.php use "ORDER BY id"

Ben G. McCullough wrote:

I think I have a flaw of logic in trying to find the correct page in a mutli-page sql result.

Goal - find the correct page [results.php?page=x] when linking from another page.

Current method - loop through a pagination function looking for the matching $id in an array [simplified for illustration]:

[find $maxpages]
$page =1;
$catch=array();
while($page <= $maxpages) {
    [set start #]
    $result = [get sql results - limit  $startnumber, 12]
    while($record = mysql_fetch_array($result)) {
        extract($record);
        $catch[] = $found_id;
        }
    if(in_array($real_id, $catch, TRUE)) {
        $here = $page;
        }
    $page++;
    }

echo "results.php?page=$here";

I never seem to get a "true" return on in_array(), and in testing, I don't seem to be getting a full result set with my look up.

I feel that I am missing something in the logic - or I am approaching this from the wrong direction.

I originally wanted to do the while test as "if in_array is FALSE, continue loop" but I couldn't get that to work at all.

Thank you for any help you can give this newbie.


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to