pickachu Posted November 2, 2007 Share Posted November 2, 2007 Im having problem with my pagination script. It does not show the second page, here's my code.. <?php $pagetitle = 'Articles'; $active = '3'; include('../includes/header.php'); $dbcnx = mysql_connect("localhost", "root", "alphonse"); mysql_select_db("articles"); echo '<!-- content-wrap starts here --> <div id="content-wrap"> <div id="sidebar" > <h3 class="clear">Login</h3>'; echo '<p>'; include('../includes/sidebar.php'); echo '<div id="main"> <div class="box">'; $id = $_GET['ID']; if(is_numeric($id)){ $sql = 'SELECT * FROM articles WHERE ID = "'.$id.'"'; // Query the database $sqlresult = mysql_query($sql); while ($row = mysql_fetch_assoc($sqlresult)) { echo '<h1>' .$row['artTITLE'].'</h1>'; echo '<p>Added on: <cite>'.$row['artTIME'].'<cite></p>'; echo '<p>'.$row['Content'].'</p>'; $artID = $row['ID']; } } else { echo '<h3>Article List</h3>'; echo '<p>Here are a list of articles which I found to be useful. Hope it\'ll be the same to you as it is for me.</p>'; } // adding check if login if (!$pun_user['is_guest'] && is_numeric($id)){ $form = ('<form action="../addcomment.php" method=post name="commentform"> <legend>Comment Title: </legend> <input type="text" name="posttitle" size="23" value=""><br /> <legend>Your Comment</legend> <br /> <textarea cols=44 rows=6 name="posttxt" size=20 wrap="VIRTUAL" onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea><br /> <input type=hidden name=assume value=true> <input type=hidden name="articleID" value='.$artID.'> <input readonly type=text name=remLen size=3 maxlength=3 value="125" style="margin-left:310px"> <br /> <input type="submit" value="submit""></form>'); echo ' <h3>Comments</h3> <p style="text-indent:1px"><cite>You will be posting as '.pun_htmlspecialchars($pun_user['username']).'</cite><br />'; echo $form.'</p></div>'; } else if(!is_numeric($id)) { echo ' '; } else { echo '<p>Please register or login first<a href="#"> here</a> to be able to comment.</p>'; } // end all div //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $data = mysql_query("SELECT * FROM comtbl") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 4; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //$result = mysql_query("SELECT * FROM comtbl WHERE article_ID='$id' ORDER BY postID DESC"); //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query("SELECT * FROM comtbl WHERE article_ID=$id $max ") or die(mysql_error()); //This sets the range to display in our query while ($row = mysql_fetch_array($data_p) ) { $msgTxt = $row["postTXT"]; $msgId = $row["postID"]; $SigName = $row["posterNAME"]; $SigDate = $row["postTIME"]; $msgTitle = $row["postTITLE"]; $imgID = $row["imgID"]; $url = $row["posterEMAIL"]; if (!$url) { $url = "#"; }else{ $stat = $url; $url = "mailto:" . $url . ""; $post = '<p><b>'.$msgTitle.'</b><br />'.$msgTxt.'</p>'; $poster = '<p class="comments align-right"> Post ID:'.$msgId.', <a href='.$url.'>'.$SigName.'</a></p>'; } echo '<div class="box">'.$post.$poster.'</div>'; // should end the while loop } echo "<p>"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a href='index.php?pagenum=1&ID=$id'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='index.php?pagenum=$previous&ID=$id'> <-Previous</a> "; } //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='index.php?pagenum=$next&ID=$id'>Next -></a> "; echo " "; echo " <a href='index.php?pagenum=$last&ID=$id'>Last ->></a> "; } echo '</div></div></div>'; include('../includes/footer.php'); ?> How do I fix this? Link to comment https://forums.phpfreaks.com/topic/75782-second-page-of-pagination-not-showing-help/ Share on other sites More sharing options...
Psycho Posted November 2, 2007 Share Posted November 2, 2007 In this code <?php if (!(isset($pagenum))) { $pagenum = 1; } ?> $pagenum is not set, so it will always be set to 1. You need to check for $_GET['pagenum'] Change to: <?php $pagenum = (is_int($_GET['pagenum']) && $_GET['pagenum']>=0)?$_GET['pagenum']:1; ?> Link to comment https://forums.phpfreaks.com/topic/75782-second-page-of-pagination-not-showing-help/#findComment-383567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.