Ben G. McCullough wrote:

I agree - my solution is VERY resource intensive, but I think I may have over simplified my question.

Each item is listed by two categories, $medium and $period. Users can get to the item via a 'browse' of either category. I want to user to be able to get back to the browse page they came from, or go to the other listing.
Pass current url to the next page, or only the relevant variables, then on the next page build the url from suplied variables.

To compound the issue - items are ordered by $sku, not $id.

So the select statement would look more like this:

SELECT COUNT(*)/12 FROM table WHERE medium = $medium ORDER BY $sku
You need to find out $sku of the current row and use

SELECT COUNT(*)/12 FROM table WHERE medium = $medium AND $sku <= $current_sku


But how would I find the page?


I had figured the only way was to actually go through each loop of pages looking for the $id, which is not working, and takes a lot of resources.

While this is only a test project, this issue is based on a real - world problem.

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