I have had this code on a site... and it seems to work... all except it is stuck on page 1. It will only display the first page of results and does not display the previous or next page. What could be wrong ? Here it is if anyone should be kind enough to take a look: <? // ============== // Configuration // ============== $perpage = "100"; // How many results to show per page $pageshow = "20"; // How many pages you want to show in the direction bar $records = mysql_fetch_array(mysql_query("select count(*) as results from articles")); $page_num = ceil($records[results] / $perpage); $page = ($page) ? $page : 1; $vstart = $perpage * ($page-1); $page_start = floor(($page-1)/ $pageshow ) * $pageshow ; $page_end = $page_start + $pageshow; for ($p=$page_start+1 ; ($p <= $page_end) && ($p <= $page_num) ; $p++ ) { if ($page == $p) { $direct_bar .= "<b>$p</b> "; } else { $direct_bar .= "<a href='/test/allarticles/?page=$p'>$p</a> "; } } if ($records[results] > $vstart+$perpage ) { $next_p=$page+1; $next_list = "<a href='/test/allarticles/?page=$next_p'>Next >></a> \n"; } if ($page>1) { $prev_p=$page-1; $prev_list="<a href='/test/allarticles/?page=$prev_p'><< Prev</a>\n"; } // Below will show the page numbers // Print "Pages: $prev_list : $direct_bar : $next_list<br /><br />"; $query = "SELECT ID, Category, Author, Email, Title, ArticleBody, ArticleBlurb, DateSub, DateAct, URL, Active FROM articles ORDER BY DateSub DESC limit $vstart,$perpage"; $query_result = mysql_query($query) or die("<b>MySQL Error:</b> " . mysql_error()); //while while ($GetPosts = mysql_fetch_array($query_result)) { $ArtID = $GetPosts['ID']; $ArtCategory = $GetPosts['Category']; $ArtAuthor = $GetPosts['Author']; $ArtEmail = $GetPosts['Email']; $ArtTitle = $GetPosts['Title']; $ArtURL = $GetPosts['ID']; $ArtTitle2 = str_replace(" ", "_", $ArtTitle); $ArtTitle2 = strtolower($ArtTitle2); $categorysql = mysql_query ("SELECT ID, Name FROM category WHERE ID = $ArtCategory"); $CatName = mysql_result($categorysql, 0, "Name"); //Process CatName $CatName2 = str_replace(" ", "_", $CatName); $CatName2 = strtolower($CatName2); $CatName2 = str_replace("'","",$CatName2); //Print the list Print "<li><a href='/test/article$ArtURL' title='$ArtTitle'>$ArtTitle</a></li></b>"; } Print "<br /><br /><center>Pages $prev_list $direct_bar $next_list</center><br />"; ?> PHP:
Well, where exactly do you set what $page is? I see you have $page = ($page) ? $page : 1; but where does it set it initially? It's always going to set it to 1 if no other value was ever set. I assume you'd want something like $page = $_GET['page']; above that at some point or whatever your URL value is (or maybe it's a POST value?).
Thank You... That was it: $page = $_GET['page']; PHP: I added the above code and now I have more than 1 page Now to (*maybe*) add a last page link. I am guessing I will have to add another variable ($page_end ?) and define that somehow... then I could just add it to the last print statement. Am I on the right track here ?