www.webdeveloper.com
Results 1 to 2 of 2

Thread: Pagination With Sorting Order

  1. #1
    Join Date
    Apr 2009
    Posts
    346

    Pagination With Sorting Order

    I have a catalog of products that each can exist in multiple sub_categories. The products are displayed across several pages with pagination. The problem is that there is a sort order associated with each product (1, 2, 3, etc...), but there are duplicate sort numbers. For instance, many products may have a sort number of 5, or 0. Without pagination it works fine, but with pagination I'm getting products repeated across pages, and some products not showing up.

    Here are the two tables being referenced:

    products
    id, product_name, sort

    sub_categories
    id, product_id, category, sub_category

    Here's the SQL statement that takes place after pagination determines the total number of rows:

    PHP Code:
    $query mysql_query("SELECT sub_categories.product_id, products.sort, products.product_name, FROM sub_categories, products WHERE sub_categories.category = '$category' AND sub_categories.product_id = products.id ORDER BY products.sort ASC LIMIT $offset$rowsperpage"); 
    As is now, several products are repeated on subsequent pages and an equal number of other products don't show at all.

    Any suggestions on making this work or maybe modifying the sorting method?

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    $query = mysql_query("SELECT DISTINCT sub_categories.product_id, products.sort, products.product_name
    FROM sub_categories, products
    WHERE sub_categories.category = '$category' AND sub_categories.product_id = products.id
    ORDER BY products.sort ASC LIMIT $offset, $rowsperpage");

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles