scmeeker Posted June 14, 2010 Share Posted June 14, 2010 I'm trying to add the Paginator script to my web page and it's almost there BUT it's bringing up all the records from my database instead of the select number of records. I'm posting my PHP code below (purposely leaving out my MySql connections), then I've attached the PHP reference file: paginator.class.php that's referenced in the code. Thanks for your help! <?php include('paginator.class.php'); $mysqli = mysqli_connect("", "", "", ""); if (mysqli_connect_errno()) { printf("Connect falied: %s\n", mysqli_connect_error()); exit (); } else { $sql = "SELECT * FROM product"; $res = mysqli_query($mysqli, $sql); $num_rows = mysqli_fetch_array($res); $pages = new Paginator; $pages->items_total = $num_rows[0]; $pages->mid_range = 9; // Number of pages to display. Must be odd and > 3 $pages->paginate(); if ($res) { while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) { $detail = $newArray['id']; $photo = $newArray['photo']; $id = $newArray['title']; $price = $newArray['price']; list($width) = getimagesize($photo); // set the maximum width of the image here $maxWidth = 100; if ($width > $maxWidth) echo "<p><a href=\"painting.php\"><img alt=\"Image\" width=\"{$maxWidth}\" src=\"{$photo}\" /></a>"; echo " Title: ".$id." Price: ".$price."<br/"; } }else { printf("Could not retrieve records: %s\n", mysqli_error($mysqli)); } mysqli_free_result($res); mysqli_close($mysqli); } ?> <br /> <br /> <?php echo $pages->display_pages(); echo "<span class=\"\">".$pages->display_jump_menu().$pages->display_items_per_page()."</span>"; echo "<p class=\"paginate\">Page: $pages->current_page of $pages->num_pages</p>\n"; ?> <br /> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/204775-paginator-help-displays-all-records-instead-of-number-requested/ Share on other sites More sharing options...
rwwd Posted June 14, 2010 Share Posted June 14, 2010 Hi there scmeeker, one thing jumps out:- $res = mysqli_query($mysqli, $sql); $num_rows = mysqli_fetch_array($res); change to:- $res = mysqli_query($mysqli, $sql); $num_rows = mysqli_num_rows($res); $pages->items_total = $num_rows;// then know off the array reference this will just return what you want, and should be a little bit better. Cheers, Rw Link to comment https://forums.phpfreaks.com/topic/204775-paginator-help-displays-all-records-instead-of-number-requested/#findComment-1072101 Share on other sites More sharing options...
scmeeker Posted June 14, 2010 Author Share Posted June 14, 2010 Thanks Rw. I tried what you suggested but all the records are still coming up. I was also confused when you said "//then know off the array reference." What did you mean by that? $res = mysqli_query($mysqli, $sql); $num_rows = mysqli_num_rows($res); $pages->items_total = $num_rows;// then know off the array reference Any other suggestions? Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/204775-paginator-help-displays-all-records-instead-of-number-requested/#findComment-1072128 Share on other sites More sharing options...
scmeeker Posted June 18, 2010 Author Share Posted June 18, 2010 Still stuck on this and hoping for some help. Thanks! Link to comment https://forums.phpfreaks.com/topic/204775-paginator-help-displays-all-records-instead-of-number-requested/#findComment-1073699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.