edrew04 Posted January 20, 2009 Share Posted January 20, 2009 finishing touches for my php project news. please help the requirements are the following for the news.class.php: 1. In index page, it must display 5 contents per page and sorted in descending oder base on submitDate of the content. 2. And the index page, must contain paging/ pagination at the lower right portion here are the codes: news.class.php <?php class news{ var $newsDir = "news"; var $newsList; var $newsCount = -1; function getNewsList( ){ $this->newslist = array(); if ($handle = @opendir($this- >newsDir) ) { while ($file = readdir($handle) ) { if (!is_dir($file) ) { $this->newsList[ ] = $file; } } } rsort($this- >newsList) ; return $this->newsList; } function getNewsCount( ){ } 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 = ""; foreach($newsData as $value){ $newsContent. =$value; } echo "<tr><th align='left' >$newsTitle< /th>"; echo "<tr><td colspan='2'> ".$newsContent. "<br/><td/ ></tr>"; echo "<th class='right' >$submitDate< /th></tr> "; } } function displayAddForm( ){ ?> <script language="javascrip t" type="text/javascri pt" src="js/tiny_ mce.js">< /script> <script language="javascrip t" type="text/javascri pt"> 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" ></center> </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,$newsTitl e."\n"); fwrite($f,$submitDa te."\n"); fwrite($f,$newsCont ent."\n") ; fclose($f); header('Location: index.php' ); } } ?> here is 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> here is admin.php <?php #News administrator panel ?> <?php require_once("news.class.php"); $newsHandler = new news(); if (!isset($_POST['submit'])){ ?> <!DOCTYPE HTML PUBLIC"-//W3C//DTD XHTML 1.0 Transitionla//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/ Share on other sites More sharing options...
MadTechie Posted January 20, 2009 Share Posted January 20, 2009 And the question is ? also.. clean up the code the formatting makes it hard to read cleaned up (formatting) <?php class news { var $newsDir = "news"; var $newsList; var $newsCount = - 1; function getNewsList () { $this->newslist = array(); if ($handle = @opendir($this->newsDir)) { while ($file = readdir($handle)) { if (! is_dir($file)) { $this->newsList[] = $file; } } } rsort($this->newsList); return $this->newsList; } function getNewsCount () {} 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 = ""; foreach ($newsData as $value) { $newsContent .= $value; } echo "<tr><th align='left' >$newsTitle< /th>"; echo "<tr><td colspan='2'> " . $newsContent . "<br/><td/ ></tr>"; echo "<th class='right' >$submitDate< /th></tr> "; } } 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"></center> </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'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-740834 Share on other sites More sharing options...
edrew04 Posted January 22, 2009 Author Share Posted January 22, 2009 how to code,where in, in index page, it must display 5 contents per page and sorted in descending order base on submitDate of the content. And the index page, must contain paging/ pagination at the lower right portion And the question is ? also.. clean up the code the formatting makes it hard to read cleaned up (formatting) <?php class news { var $newsDir = "news"; var $newsList; var $newsCount = - 1; function getNewsList () { $this->newslist = array(); if ($handle = @opendir($this->newsDir)) { while ($file = readdir($handle)) { if (! is_dir($file)) { $this->newsList[] = $file; } } } rsort($this->newsList); return $this->newsList; } function getNewsCount () {} 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 = ""; foreach ($newsData as $value) { $newsContent .= $value; } echo "<tr><th align='left' >$newsTitle< /th>"; echo "<tr><td colspan='2'> " . $newsContent . "<br/><td/ ></tr>"; echo "<th class='right' >$submitDate< /th></tr> "; } } 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"></center> </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'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-742960 Share on other sites More sharing options...
haku Posted January 22, 2009 Share Posted January 22, 2009 This will get you sorter for the first five queries orded by date descending: "SELECT contents FROM table ORDER BY submitDate DESC LIMIT 5" Next: pagination isn't something that can be explained in a thread. Google it - there are more tutorials on how to do pagination than you can shake a stick at. Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-742964 Share on other sites More sharing options...
edrew04 Posted January 22, 2009 Author Share Posted January 22, 2009 Where will I put this code on my index.php(my previous codes above)? "SELECT contents FROM table ORDER BY submitDate DESC LIMIT 5" Next: pagination isn't something that can be explained in a thread. Google it - there are more tutorials on how to do pagination than you can shake a stick at. Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-743019 Share on other sites More sharing options...
haku Posted January 22, 2009 Share Posted January 22, 2009 Use it in your database query. Didn't you write that code? Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-743027 Share on other sites More sharing options...
edrew04 Posted January 23, 2009 Author Share Posted January 23, 2009 Use it in your database query. Didn't you write that code? will i write it any where on the code index.php including the "double quotes"? Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-743863 Share on other sites More sharing options...
haku Posted January 23, 2009 Share Posted January 23, 2009 You can't use the code I gave you - it was an example. You will have to swap in your own table and column names, and put it in the spot where you are doing your database query. If you were the one who wrote the script, this shouldn't be a problem. And its really hard to understand your posts if you keep including your comments in my quotes. Hint: Put your comments outside the opening and closing quote tags. Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-743921 Share on other sites More sharing options...
edrew04 Posted February 25, 2009 Author Share Posted February 25, 2009 by the way, the codes that i posted here is the code from our professor, ms. Cabrera Quote Link to comment https://forums.phpfreaks.com/topic/141531-finishing-touches-for-my-php-project-news-please-help/#findComment-770785 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.