Definitely need to use LIMIT in your SQL query here. The trick to making this as simple as possible, though, is creating PHP functions for things in a general way. You will need to track certain variables for your user and you can save these in a PHP SESSION or just in regular variables.
function calc_first_record() { return ($_SESSION['user_page'] - 1) * $_SESSION['products_per_page']; } function calc_max_pages_in_query($count_recs_returned_in_query) { return ceil($count_recs_returned_in_query / $_SESSION['prods_per_page']); } Then create a function (or functions) to display your records in a general way so you can pass in the given query. You don't want to be rewriting logic that's the same for your given categories if at all possible. So pass in the query to the display function and let your display function cycle through the results. If your user vars are saved in a SESSION, you don't need to add them to your list of function inputs as they are globally available, so if you don't save things like the number of products to be shown per page in the user's SESSION, you will need to pass this into the function. Same thing for the sort ascending / descending. As soon you make 10 products per page on a descending sort, you'll need 20 per page on an ascending sort, so go ahead and plan for that now. You can see the vars in SESSIONS above, but if you don't use SESSIONS the display function would look more like the following: function display_products_page( $query_type, $products_per_page, $sort_order, $first_product_to_display, $max_pages_in_query) { // you'll need to do a SWITCH on your $query_type to load // your query in a variable to be executed later // your SQL query will use the LIMIT clause with the first number // being $first_product_to_display and the last number being // ($first_product_to_display + $products_per_page) and your // sort being $sort_order switch ($query_type) { case 'cameras': $query = 'SELECT....'; break; case 'cell_phones': $query = 'SELECT....'; break; // add as many categories as you need here in your CASEs default: break; } // now that your $query variable is loaded with everything // you need in a general way, you can run it and display your results $rq = mysql_query($query) or die(mysql_error()); $r = mysql_fetch_array($rq); while ($r != NULL) { $prod_name = $r{'prod_name']; $prod_image = $r{'prod_image']; $prod_description = $r{'prod_description']; $prod_price = $r{'prod_price']; // display your product in HTML here using your // name, image, description, price variables echo "$prod_name $prod_image $prod_description $prod_price"; $r = mysql_fetch_array($rq); } // you can also use $max_pages_in_query to display your various // page links in a pagination function display_page_links($query_type, $max_pages_in_query); } Hope this helps! Ken Krauss Kansas City Web Development http://www.kcwebdev.com --- In php_mysql@yahoogroups.com, <sc.mem...@...> wrote: > > Use LIMIT in your SQL query. > > >