elviapw Posted March 3, 2009 Share Posted March 3, 2009 I've created a website where users can post entries. I want to alter the PHP so that after displaying the 10 most recent posts, the user can click "next" to see the next ten. I don't really know how to go about this, though I'm sure it's a common problem. here is the code so far: <?php $dbh = mysqli_connect("--", "--", "--", "--"); $sql = "SELECT Title,Content,Date, Human, image_url, image_url2, image_url3, id FROM Posts ORDER BY id DESC"; $query = mysqli_query($dbh,$sql); echo "<html> <head></head><title>velcome</title> <body><center> <font style='color:#00FFFF;font-family:futura,helvetica; font-size:240px'> TITLE </font></center> <div style='background: white; border-width: medium; font-family:times; font-size:16px; float: left; position: absolute; top: 615px; width:80px'> <br/><br/><br/><br/> <a style='text-decoration:none' href='http://eadersdigest.com/projecks/projecks.html'><font color='#99CC00'><i>projecks</i></font></a><br/> <a style='text-decoration:none' href='http://--/members.html'><font color='#99CC00'><i>digestion</i></font></a> <br/><br/><br/> frendz >><br/> <a style='text-decoration:none' href='http://--/login.html'><font color='#FF6600'><i>LAWG IN</i></font></a> <br/><br/> </div> <table style='border-style:solid; margin-left: auto; margin-right: auto; margin-top: 40px; width:800px' bordercolor='#999999' cellpadding='20'>"; if($query) { $rows = mysqli_num_rows($query); for($i = 0; $i < $rows; $i++) { $feed = mysqli_fetch_assoc($query); $title = $feed['Title']; $post = $feed['Content']; $date = $feed['Date']; $id = $feed['id']; $human = $feed['Human']; $pic = $feed['image_url']; $pic2 = $feed['image_url2']; $pic3 = $feed['image_url3']; echo "<tr >\n"; echo "<td >\n"; echo "<a href='archive.php'><font face='Georgia, Times New Roman, Times, serif' color='#999999'>$title</font></a>\n"; echo "<div align='right'>$date</div><br/>"; echo "<div align='right'>$human</div><br/>"; echo " <p>$post</p><br/>\n"; if ( !empty($feed['image_url']) ) { echo "<img src= '$pic'/><br/><br/>"; } else { echo " "; } if ( !empty($feed['image_url2']) ) { echo "<img src= '$pic2'/><br/><br/>"; } else { echo " "; } if ( !empty($feed['image_url3']) ) { echo "<img src= '$pic3'/><br/><br/>"; } else { echo " "; } echo "<div align='right'>"; echo " <a style='text-decoration:none' href='comment1.php?id=$id&Title=$title&Content=$post&Date=$date&image_url=$pic&image_url2=$pic2&image_url3=$pic3'><font color='#FFCC33' style='font-style:italic' face='Times'>comment on this post</font><br/></a>\n"; echo " <a style='text-decoration:none' href='delete.php?id=$id&Title=$title&Content=$post&Date=$date&image_url=$pic&image_url2=$pic2&image_url3=$pic3'><font color='#66FF99' style='font-style:italic' face='Times'>delete this post</font><br/></a>\n"; $sql2 = "SELECT comment_id FROM Comments WHERE comment_id=$id"; $query2 = mysqli_query($dbh,$sql2); if($query2) { $feed2 = mysqli_fetch_assoc($query2); $commentid = $feed2['comment_id']; if ( !empty($feed2['comment_id']) ) { echo " <a style='text-decoration:none' href='viewcomments.php?id=$id&Title=$title&Content=$post&Date=$date&image_url=$pic&image_url2=$pic2&image_url3=$pic3'><font color='#66FF99' style='font-style:italic' face='Times'> see comments on this post</font><br/></a>\n"; } else { echo "no comments yet"; } } echo "</div><hr />"; echo "</td >\n"; echo "</tr>\n"; } echo "</table>\n"; echo "</center>"; echo"<a style='text-decoration:none' href='http://--/archive.php'><font color='#FF6600'><center><br/>archive</center></font></a>"; } echo"</body> </html>" ?> Link to comment https://forums.phpfreaks.com/topic/147680-how-to-create-set-number-of-rows-and-then-continue-on-next-page/ Share on other sites More sharing options...
genericnumber1 Posted March 3, 2009 Share Posted March 3, 2009 Google "php pagination" Link to comment https://forums.phpfreaks.com/topic/147680-how-to-create-set-number-of-rows-and-then-continue-on-next-page/#findComment-775227 Share on other sites More sharing options...
Floydian Posted March 3, 2009 Share Posted March 3, 2009 In your query, you would need to add a limit x z where x is the starting point, and z is the number of results. In order to know if a "next" link is needed, run a select count(*) query so you know the total number of results in the set. Your next link should contain a value for the starting point. So page 3, with 10 rows per page would pass a 30 as the starting point. Hope that helps. Link to comment https://forums.phpfreaks.com/topic/147680-how-to-create-set-number-of-rows-and-then-continue-on-next-page/#findComment-775230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.