hi, i have an online store with some products. i want to split in pages when the page has more than 8 records. how i can do this? this is my php code: <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("storedb", $con); $result = mysql_query("SELECT * FROM products WHERE cat='".$cat."' AND status=1 ORDER BY pricer"); ?> PHP: any idea is acceptable thanks in advance.
Use LIMIT in your query. What you want is called pagination. If you do a google search you'll find lots of examples.
//Copyright Matthew Bell 2008. BSD License. http://www.matthewbell.eu function paginate($per_page, $current_page, $before, $after, $total_pages, $get_key) { $get = ''; $output = ''; if ($current_page <= 0) $current_page = 1; if ($total_pages < 1) $total_pages = 1; foreach ($_GET as $k=>$v) { if ($k != $get_key) { $get .= $k.'='.$v.'&'; } } $x = $current_page-$before; if ($x <= 0) $x = 1; for($i=$x;$i<$current_page;$i++) { $output .= '<a href="'.$_SERVER['PHP_SELF'].'?'.$get.$get_key.'='.$i.'">Page '.$i.'</a> '; } $output .= 'Page '.$current_page. ' of '.$total_pages.' '; for($i=$current_page+1;$i<=$current_page+$after && $i <= $total_pages;$i++) { $output .= '<a href="'.$_SERVER['PHP_SELF'].'?'.$get.$get_key.'='.$i.'">Page '.$i.'</a> '; } return $output; } PHP: