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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
:
<?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');
}
}
?>


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux