foreverhex Posted July 13, 2006 Share Posted July 13, 2006 I have just started learning pagination. And I looked up this tutorial on here [url=http://www.phpfreaks.com/tutorials/43/0.php]http://www.phpfreaks.com/tutorials/43/0.php[/url]. I altered the code a bit but the main frame is there. My question is why does the link not work for next page? I know there is an else statement that says if there is no next page than it isnt a link... but there should be a next page! Grr pls help. Here is my code:[code]<?php$orderuser = 'signupdate';include 'db.php';//db connect $limit = 2; $query_count = "SELECT count(*) FROM users"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM users ORDER BY $orderuser LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } $bgcolor = "#110000"; // light gray echo '<table class=ourfamily align=left valign=top>'; while($row = mysql_fetch_array($result)){ if ($bgcolor == "#110000"){ $bgcolor = "#110000"; }else{ $bgcolor = "#110000"; } echo '<tr bgcolor=' . $bgcolor . '><td width="150"><a href="http://www.syblings.net/user.php?id=' . $row["user"] . '"><img src="/images/avatar/' . $row["user"] . '.jpg" width="150" border=0></a></td><td valign=top>'; echo('<b>' . $row["user"] . '</b>'); echo '<br /><br />'; echo('<b>Medium(s):</b> ' . $row["medium"]); echo '<br />'; echo('<b>Location:</b> ' . $row["location"]); echo '<br />'; echo('<b>Interests:</b> ' . $row["interests"]); echo '</td></tr><tr><td colspan=2><hr width=90% color=#330000 align=center></td></tr>'; } echo '<tr><td colspan=2 align=center>'; if($page != 1){ $pageprev = $page--; echo '<a href=\"ourfamily.php?page=$pageprev\">PREV' . $limit . '</a> '; }else{ echo 'PREV' . $limit . ' '; } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i . " "); }else{ echo("<a href=\"ourfamily.php?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i . " "); }else{ echo ' <a href="ourfamily.php?page=$i">$i</a> '; } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo ' <a href="ourfamily.php&page=$pagenext">NEXT" . $limit . "</a>'; }else{ echo ' NEXT' . $limit; } mysql_free_result($result);echo '</td></tr></table>';?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/14542-pagination-issue-solved/ Share on other sites More sharing options...
hitman6003 Posted July 14, 2006 Share Posted July 14, 2006 Look at this block of code:[code]if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo ' <a href="ourfamily.php&page=$pagenext">NEXT" . $limit . "</a>'; }else{ echo ' NEXT' . $limit; }[/code]Particularly, this line:echo ' <a href="ourfamily.php&page=$pagenext">NEXT" . $limit . "</a>';You are not escaping the single quotes to have the value of the variable inserted. Change that line to be:echo ' <a href="ourfamily.php&page=' . $pagenext . '">NEXT ' . $limit . '</a>';And, looking again at your code, you are doing it with the similar blocks of code above that. Make sure you change all fo them so that you are not trying to insert a variable while it is inside of the single quotes.Remember, single quotes means php will print EXACTLY what is there, double quotes it will substitute variable values for the variable. Quote Link to comment https://forums.phpfreaks.com/topic/14542-pagination-issue-solved/#findComment-57696 Share on other sites More sharing options...
foreverhex Posted July 14, 2006 Author Share Posted July 14, 2006 LOL. Well that was all it was. thx Quote Link to comment https://forums.phpfreaks.com/topic/14542-pagination-issue-solved/#findComment-57745 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.