How to view most recent 25 posts

More
17 years 10 months ago #324 by Pete
Ok, here is how your code should look like:
Code:
<?php // File list.php ==================================================================== include($_SERVER['DOCUMENT_ROOT']."/horror-stories/header.php"); $page = $_GET['page']; $order= $_GET['order']; if ($page == "") { $page = 1; } $fwd = $page - 1; $rwd = $page +1; // Setting the default values for number of records per page ------------------------- $perpage = 25; $file = $_SERVER['DOCUMENT_ROOT']."/$state.php"; //$file = $_SERVER['DOCUMENT_ROOT']."/horror-stories/data/$state.txt"; $file = "horror-stories/data/" . $state . ".txt"; include($_SERVER['DOCUMENT_ROOT']."/".$file); // Reading in all the records, putting each guestbook entry in one Array Element ----- $handle = fopen($file, "r"); if (filesize($file) == 0){ // mpg are there any entries to display print "There are currently no entries to display"; // mpg no inform user } else { $datain = fread($handle, filesize($file)); fclose($handle); $out = explode("<!-- E -->", $datain); $outCount = count($out) - 1; $j = $outCount-1; if ($order == "desc") { for ($i=0; $i<=$outCount; $i++) { $lines[$j] = unserialize($out[$i]); $j = $j - 1; } } else { for ($i=0; $i<=$outCount; $i++) { $lines[$i] = unserialize($out[$i]); } } // Counting the total number of entries (lines) in the data text file ---------------- $result = count($lines); $count = $result-1; //echo $count."<br>"; // Caclulate how many pages there are ---------------------------------------- if ($count == 0) { $totalpages = 0; } else { $totalpages = intval(($count - 1) / $perpage) + 1; } $page = $totalpages - ($page - 1); $end = $count - (($totalpages - $page) * $perpage); $start = $end - ($perpage - 1); if ($start < 1) { $start = 1; } //$end = ($perpage * $page) - 1; //$start = $end - $perpage; if ($start < 0) { $start = 0; } //for ($i = $end; $i>=($start-1); $i--) //for ($i = 0; $i<$outCount; $i++) //for ($i=$start-1; $i<$end; $i++) for ($i=$end-1; $i>$start-2; $i--) { //echo $i."<br>end-".$end."-start-".$start; echo "<table bgcolor=#EFEFEF bordercolor=#C0C0C0 border=1 width=500 cellspacing=0 cellpadding=10><tr><td background=\"/horror-stories/images/toolbar.jpg\" height=\"20\"></td></tr><tr><td>"; echo "<b>$listDatetxt: </b>"; $lines[$i]->showDate(); echo "<br><b>$listnametxt: </b>"; $lines[$i]->showFrom(); echo "<br><b>$listemailtxt: </b><a href=\"mailto:"; $lines[$i]->showEmail(); echo "\">"; $lines[$i]->showEmail(); echo "<br><br><b>$listMessagetxt: </b>"; $lines[$i]->showMessage(); echo "</td></tr></table><br>"; } echo "<center>"; echo "<a href=\"/".$state."all.php\">List ALL Entries"; echo "</center>"; } // mpg end if include($_SERVER['DOCUMENT_ROOT']."/footer.php"); ?>

And the list all entries page would be like this:
Code:
<?php // File $stateall.php ==================================================================== include($_SERVER['DOCUMENT_ROOT']."/horror-stories/header.php"); $page = $_GET['page']; $order= $_GET['order']; if ($page == "") { $page = 1; } $fwd = $page - 1; $rwd = $page +1; // Setting the default values for number of records per page ------------------------- $perpage = 25; $file = $_SERVER['DOCUMENT_ROOT']."/$state.php"; //$file = $_SERVER['DOCUMENT_ROOT']."/horror-stories/data/$state.txt"; $file = "horror-stories/data/" . $state . ".txt"; include($_SERVER['DOCUMENT_ROOT']."/".$file); // Reading in all the records, putting each guestbook entry in one Array Element ----- $handle = fopen($file, "r"); if (filesize($file) == 0){ // mpg are there any entries to display print "There are currently no entries to display"; // mpg no inform user } else { $datain = fread($handle, filesize($file)); fclose($handle); $out = explode("<!-- E -->", $datain); $outCount = count($out) - 1; $j = $outCount-1; if ($order == "desc") { for ($i=0; $i<=$outCount; $i++) { $lines[$j] = unserialize($out[$i]); $j = $j - 1; } } else { for ($i=0; $i<=$outCount; $i++) { $lines[$i] = unserialize($out[$i]); } } // Counting the total number of entries (lines) in the data text file ---------------- $result = count($lines); $newend = count($lines); $count = $result-1; //echo $count."<br>"; // Caclulate how many pages there are ---------------------------------------- if ($count == 0) { $totalpages = 0; } else { $totalpages = intval(($count - 1) / $perpage) + 1; } $page = $totalpages - ($page - 1); $end = $count - (($totalpages - $page) * $perpage); $start = $end - ($perpage - 1); if ($start < 1) { $start = 1; } //$end = ($perpage * $page) - 1; //$start = $end - $perpage; if ($start < 0) { $start = 0; } //for ($i = $end; $i>=($start-1); $i--) //for ($i = 0; $i<$outCount; $i++) //for ($i=$start-1; $i<$end; $i++) for ($i=$newend-1; $i>$start-2; $i--) { //echo $i."<br>end-".$end."-start-".$start; echo "<table bgcolor=#EFEFEF bordercolor=#C0C0C0 border=1 width=500 cellspacing=0 cellpadding=10><tr><td background=\"/horror-stories/images/toolbar.jpg\" height=\"20\"></td></tr><tr><td>"; echo "<b>$listDatetxt: </b>"; $lines[$i]->showDate(); echo "<br><b>$listnametxt: </b>"; $lines[$i]->showFrom(); echo "<br><b>$listemailtxt: </b><a href=\"mailto:"; $lines[$i]->showEmail(); echo "\">"; $lines[$i]->showEmail(); echo "<br><br><b>$listMessagetxt: </b>"; $lines[$i]->showMessage(); echo "</td></tr></table><br>"; } echo "<center>"; echo "<a href=\"/".$state.".php\">Back To Previous Page"; echo "</center>"; } // mpg end if include($_SERVER['DOCUMENT_ROOT']."/footer.php"); ?>

DigiOz Webmaster
www.digioz.com

Please Log in or Create an account to join the conversation.

More
17 years 10 months ago #325 by tunafabulous
Hi Pete,

I think I have complicated things by describing how this guestbook I'm working on actually works. What I need seems quite simple, I'm just not that good with PHP.

Basically what I can't figure out how to do is "SELECT the 25 most recent entries" in the $state.txt files. The current code already shows all of the entries, so the "view all" feature is not an issue.

Is it possible to set the date fields with a variable name and then select the 25 most recent entries?

Thanks,
Tuna

Please Log in or Create an account to join the conversation.

More
17 years 10 months ago #326 by tunafabulous
Could I somehow do an ECHO on 25 Date fields? If so, how could I impleent this with your list.php file?

Please Log in or Create an account to join the conversation.

More
17 years 10 months ago #327 by Pete

tunafabulous wrote: ... Is it possible to set the date fields with a variable name and then select the 25 most recent entries?


Yes. Simply replace:
Code:
$perpage = 10;

With this:
Code:
$perpage = 25;

That will give you the 25 most recent entries on the first page.

DigiOz Webmaster
www.digioz.com

Please Log in or Create an account to join the conversation.

More
17 years 10 months ago #328 by tunafabulous
Hi Pete,

Yes that is where the problem lies, I am aware that this is where the code should be changed, however regardless of what number I put there the pages still display "all" of the entries in the .txt files. It's almost like that variable is disabled and I thought maybe you would know of a work around.

If you have a few minutes, would it be possible for you to look at my code above and determine why this variable does not work on my pages?

Thanks!

Please Log in or Create an account to join the conversation.

Time to create page: 0.125 seconds
Powered by Kunena Forum