justAnoob Posted December 30, 2009 Share Posted December 30, 2009 Ok, I found an example online, and gave it a little tweak(not much) so I can get the idea of how pagination page numbers work. My page displays with the corrent amount of rows from the database that I want on a page. Here is the prob. When I click on a page number, the same entries are shown. Can anyone throw me a pointer. <?php include 'connection.php'; $cat = "DVDs"; $query = "SELECT id FROM my_table WHERE category = '$cat' "; $result = mysql_query($query); $count = mysql_num_rows($result); $display = 2; if (empty($startrow)) { $startrow=0; } $query2 = "SELECT thumb_1 FROM my_table WHERE category = 'DVDs' LIMIT $startrow, $display"; $result2 = mysql_query($query2); echo "<table border='0' CELLPADDING=5 STYLE='font-size:16px'>"; while ($row = mysql_fetch_array($result2)) { echo "<tr><td align='center'>"; echo '<a href="viewmovie.php?sendto='.$row['id'].'"><img src="' . $row['thumb_1'] . '" width="90" border="0" alt=""></a></td></tr>'; echo '<tr><td>'; echo '<hr width="550">'; echo "</td></tr>"; } echo "</table>"; if ($startrow > 1) { $prevrow = $startrow - $display; echo '<a href="testing2.php?startrow=$prevrow">Previous</a> '; } $pages = intval($count / $display); if ($count % $display) { $pages++; } if ($pages > 1) { for ($i=1; $i <= $pages; $i++) { $next = $display * ($i - 1); echo '<a href="testing2.php?startrow=$next">$i</a> '; } } if (!(($startrow / $display) == $pages) && $pages != 1) { $next = $startrow + $display; echo '<a href="testing2.php?startrow=$next">Next</a> '; } if ($count < 1) { echo "Nothing, sorry. Please try again."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/186654-page-links-not-working/ Share on other sites More sharing options...
sasa Posted December 30, 2009 Share Posted December 30, 2009 change if (empty($startrow)) { $startrow=0; } to $startrow = $_GET['startrow'] ? $_GET['startrow'] : 0; Quote Link to comment https://forums.phpfreaks.com/topic/186654-page-links-not-working/#findComment-985803 Share on other sites More sharing options...
justAnoob Posted December 30, 2009 Author Share Posted December 30, 2009 hey thanks, could you explain what that means? btw, it worked. Quote Link to comment https://forums.phpfreaks.com/topic/186654-page-links-not-working/#findComment-985805 Share on other sites More sharing options...
calmchess Posted December 30, 2009 Share Posted December 30, 2009 Ternary operator logic is the process of using “(condition) ? (true return value) : (false return value)” statements to shorten your if/else structures Quote Link to comment https://forums.phpfreaks.com/topic/186654-page-links-not-working/#findComment-985814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.