clint Posted October 12, 2009 Share Posted October 12, 2009 Hello Phpfreaks, I am trying to do a bit of pagination but I am coming up 1 row short for each page. I could be way off with the code or something simple, after all I am a php toddler. What I am trying to do is with a form where you select country and state, it displays your mysql data according to that selection. For testing puposes I created 13 rows in the table but when I view results it shows 9 on the 1st page and 2 on the 2nd page, leaving out 1 on each page. The column is called company and all 13 rows have data so its not like its showing but just blank rows. Here is the code: <?php include'dbc.php'; if($_GET['page']) // Is page defined? { $page = $_GET['page']; // Set to the page defined }else{ $page = 1; // Set to default page 1 } $max = 10; // Set maximum to 10 $cur = (($page * $max) - $max); // Work out what results to show $getdata = mysql_query("SELECT * FROM sbt WHERE country LIKE '%$country%' AND state LIKE '%$state%' ORDER BY `id` DESC LIMIT $cur, $max") or die(mysql_error()); // select the results $data = mysql_fetch_array($getdata); // get the data while($user = mysql_fetch_array($getdata)) { echo $user['company'] . '<br />'; } $counttotal = mysql_query("SELECT * FROM sbt ") or die(mysql_error()); // select all records $counttotal = mysql_num_rows($counttotal); // count records $total_pages = ceil($counttotal / $max); // dive the total, by the maximum results to show if($page > 1){ $prev = ($page - 1); echo '<a href="?page=' . $prev . '">« Previous</a>'; } for($i = 1; $i <= $total_pages; $i++) // for each page number { if($page == $i) // if this page were about to echo = the current page { echo'<b>' . $i .'</b> '; // echo the page number bold } else { echo '<a href="?page=' . $i . '">' . $i . '</a> '; // echo a link to the page } } if($page < $total_pages){ $next = ($page + 1); echo '<a href="?page=' . $next . '">Next »</a>'; // echo the next page link } ?> Could someone please advise me on my wrongful 1 row short ways Thank you for taking the time to read this. Much appreciated! Link to comment https://forums.phpfreaks.com/topic/177397-solved-pagination-showing-1-row-short/ Share on other sites More sharing options...
sasa Posted October 12, 2009 Share Posted October 12, 2009 change to $getdata = mysql_query("SELECT * FROM sbt WHERE country LIKE '%$country%' AND state LIKE '%$state%' ORDER BY `id` DESC LIMIT $cur, $max") or die(mysql_error()); // select the results //$data = mysql_fetch_array($getdata); // get the data while($user = mysql_fetch_array($getdata)) { echo $user['company'] . '<br />'; } Link to comment https://forums.phpfreaks.com/topic/177397-solved-pagination-showing-1-row-short/#findComment-935340 Share on other sites More sharing options...
clint Posted October 12, 2009 Author Share Posted October 12, 2009 silly me! thanks so much for the help. I do appreciate it. All sorted now. Link to comment https://forums.phpfreaks.com/topic/177397-solved-pagination-showing-1-row-short/#findComment-935384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.