Jump to content

help on simple basic paging of 5 displays of text files per page in php


edrew04

Recommended Posts

to finnish.. how to make a basic paging of text files(no mysql used) in php?

for instance: i have this code here and a page will only display 5 text files only per page and there will be a  "next>>" button where in  , you can go to the other remaining text files and also there is the link "<<previous" where in, you can go back to the first five page you had started please help. i put comment on the counting of news in "news.class.php"

:here is

"news.class.php"

<?php
class news{
var $newsDir = 'news';
var $newsList;
var $newsCount = -1;
function getNewsList(){
$this->newsList=array();
//Open the actual directory
if($handle=@opendir($this->newsDir)){
	//Read all file form the actual directory
	while ($file=readdir($handle)){
		if(!is_dir($file)){
			$this->newsList[]=$file;
		}
	}
}
rsort($this->newsList);
return $this->newsList;
}
/*Well, I will not use the function getNewsCount(){} anymore because i had a better idea of counting the number of news*/
/*function getNewsCount(){}<-trapped in a comment hahahahahaha ^.^*/

function displayNews(){
$list = $this->getNewsList();
echo "<table class='newsList'>";
foreach($list as $value){
	$newsData=file($this->newsDir.DIRECTORY_SEPARATOR.$value);
	$newsTitle=$newsData[0];
	$submitDate=$newsData[1];
	unset($newsData['0']);
	unset($newsData['1']);
	$newsContent="";
	$i= 0;
	foreach($newsData as $value){
		$newsContent.=$value;
                
	}    
                    $numOfNews=(count($list));
                    if($numOfNews>5){
                    $numOfNextNewsPage=$numOfNews-5;
                    //$list=$numOfNextNewsPage;
                    //$NextNewsPage=$list-$numOfNextNewsPage;
                       
                       echo "<tr><th align='left'>$newsTitle</th>";
	       echo "<tr><td colspan='2'>".$newsContent."<br></td></tr>";
	       echo "<th class='right'>$submitDate</th></tr>";
                       
                       }
                         else
                         {
                         
                         echo "<tr><th align='left'>$newsTitle</th>";
	         echo "<tr><td colspan='2'>".$newsContent."<br></td></tr>";
	         echo "<th class='right'>$submitDate</th></tr>";
                         }
                         
                 
                         
}
         if($numOfNews>0 && $numOfNews<=5){
         $stringMsgNews="<b>The total number of news for today is:</b> ".$numOfNews." <b>News.</b><br>";
         echo $stringMsgNews;
         echo"</table> ";
         }
           else if($numOfNews>5){
                   $stringMsgNews="<b>The total number of news for today is:</b> ".$numOfNews." <b>News.</b><br>";
                   echo $stringMsgNews;
                   echo "The page exeeded to 5 news. click next>> to see more news"; 
                   echo"</table> ";
                   echo "<a href='http://localhost/xampp/cardano/cardano3/Project_News/index.php'><center><p><b>next>></b></p></center>";
                  }
                  else{
                  echo "";
                  echo"</table> ";
                  }
         
//echo"</table> ";
   if(sizeOf($list) ==0){
   echo "<hr color='dodgerblue' size='10%'>";
   echo "<center><p><b> No News At The Moment.</b></p><p>&nbsp</p></center> ";
   echo "<hr color='dodgerblue' size='10%'>";
  }
}
function displayAddForm(){
?>
<script language="javascript" type="text/javascript" src="js/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init ({
mode  : "textareas",
theme : "advanced",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_align : "center",
theme_advanced_toolbar_location: "top",
});
</script>
<form class="iform" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
News title:<br/>
<input type="text" name="title" size="40"/><br/><br/>
Content:<br/>
<textarea name="newstext" rows="15" cols="67"></textarea><br>
<center><input type="submit" name="submit" value="save">
</form>
<?php
}
function insertNews(){
$newsTitle = isset($_POST['title']) ? $_POST['title']:'Untitled';
$submitDate = date('Y-m-d g:i:s A');
$newsContent = isset($_POST['newstext']) ? $_POST['newstext']:'No Content';
$filename = date('YmdHis');
if(!file_exists($this->newsDir)){
	mkdir($this->newsDir);
}
$f = fopen($this->newsDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");
fwrite($f,$newsTitle."\n");
fwrite($f,$submitDate."\n");
fwrite($f,$newsContent."\n");
fclose($f);
header('Location:index.php');
}
}
?>

 

 

here is my

"index.php"

<?php
#Front End
?>
<?php
require_once
("news.class.php");
$newsHandler = new news();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>News</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="container">
<div id="header"><div id="header_left"></div>
<div id="header_main">News</div><div id="header_right"></div></div>
<div id="content">
	<?php $newsHandler->displayNews(); ?>
</div>
</div>
</body>
</html>

 

 

and this is my

"admin.php"

<?php
//News administration panel.
?>
<?php
require_once("news.class.php");
$newsHandler = new news();
if (!isset($_POST['submit'])) {
?>
<html>
<head>
<meta http-equiv = "Content-Type" content = "text/html; charset = utf-8" />
<title>News - Admin panel</title>
<link href = "style/style.css" rel = "stylesheet" type = "text/css" />
</head>
<body>

<div id = "container">
	<div id = "header"><div id = "header_left"></div>
	<div id = "header_main">News - Admin panel</div><div id = "header_right"></div></div>
	<div id = "content">
		<?php $newsHandler -> displayAddForm(); ?>
	</div>
</div>

</body>
</html>
<?php
} else {
$newsHandler->insertNews();
}
?>

 

help me here :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.