Simple News Help

Hello all, im beginner of PHP, and today i want ask you something.
I stars simple page and i download simple news script, and i design it…
But when i add news all news are on first page…
I want it to show just 10 or 15 news on home page, or if its possible to make pages Example : 1 2 3 4 -> ->| , I will show you php script of this Simple News

post.php looks like this:

[php]<?
//File to keep news in. If you are using the secure setup described in the
//readme with post.php in an .htaccessed admin dir you must update the location
//of news.txt file in the next variable.
$newsfile = “news.txt”;
//Open news.txt in read mode.
$file = fopen($newsfile, “r”);
//Table Vars The below variables are inserted verbatim into the news.txt file.
//This gives you a lot of control over how the news will look. The
//disadvantage is that if you ever decide you don’t like how these look you
//can’t change one thing like with CSS to adapt it to your liking. You will
//have to do a mass “find and replace” on the news.txt file. In other words:
//these are essentially the HTML tags that will go around your entries.
//b=begin e=end
$btable = "

“;
$btitle = “”;
$bdate = "”;
$bpost = “”;
$etable = “
”;
$etitle = “
Posted on:”;
$edate = “
”;
$epost = “

”;
//Define PHP Date format. Used for the default date form value.
$defdate=date(“m/d/Y”);
//Other notes
//The date is automatically set to todays date by using PHP to echo the
//variable of defdate. The form action uses this file itself to process the
//data.
// The If/Else statements decide what is displayed based on whether a HTTP GET
// or POST was issued by the browser. GET: If the submit button has not been
// pushed – display form. PUT: Submit button has been pushed – write data to
// text file and display confirmation message.
//IF browser does not send a POST request (ie: if submit has not been pressed)
//then display the form…
if ($_SERVER[‘REQUEST_METHOD’] != ‘POST’){
//If able to open file do…
if ($file) {
?> h2 {text-align: center}

Add news

Title:
Data:
Text:

<? } else //If can not open file complain... echo "Server: Error

Cant open the file.
Permisions??

"; } //ELSE IF browser sends a POST request. Make sure that data was actually //entered into the form and then write that data to the file.... elseif ((isset($_REQUEST["title"])) && (isset($_REQUEST["date"])) && (isset($_REQUEST["post"])) && ($_REQUEST["title"]!="") && ($_REQUEST["date"]!="") && ($_REQUEST["post"]!="")) { //The next few lines are a hacked up way to "add" text to the top of a file. //// The file is already opened in read mode. Read in all the current data //from news.txt. Save this as variable current_data. $current_data = @fread($file, filesize($newsfile)); //Now that we have saved the old data to a variable lets close the file. fclose($file); //Now we reopen the file in write mode. This FIRST blanks the file. Then will //will write the new data followed by the old data to the file. $file = fopen($newsfile, "w"); //Write all of the table variables and the text entered into the form, plus the //text that was already in news.txt to news.txt. The \n is a new line and it //simply make news.txt more beautiful. If it works display success message, if //not display failure message.

//// Fix quotes (’) in entries and change any weird
//characters (&,<,>,etc) to their html equivalents. Do the same for title and
//date. Even though it should not be needed for date.
$_REQUEST[“post”] = stripslashes(($_REQUEST[“post”]));
$_REQUEST[“date”] = stripslashes(($_REQUEST[“date”]));
$_REQUEST[“title”] = stripslashes(($_REQUEST[“title”]));
if(fwrite($file,$btable . " " . $btitle . " " . $_REQUEST[“title”] . " " . $etitle . " " . $bdate . " " . $_REQUEST[“date”] . " " . $edate . " " . $bpost . " " . $_REQUEST[“post”] . " " . $epost . " " . $etable . “\n " . $current_data))
echo “Simple News: Entry Added

The entry was added successfully.
<a href=””>Addother entry

";
else
echo “Simple News: Entry NOT Added!

Could not add entry.
Permissions??

”;
//Close the file.
fclose($file);
}
//If the browser sent a POST request but the user failed to put data in the
//form…spit out this error.
else
echo “Server: The entry wasnt added!

Cand add entry.
All fields are required.
Please back later and try again.

”;
?>
[/php]

And display.php looks like this :
[php]<?
//This file displays the news by reading it from the news.txt file. Make sure
//news.txt is chmoded 766. The CSS definitions determine how the news will
//look. To hardcode variables look into the “table vars” in post.php.
//You don’t have to use this file to display news on your page. Simply copy
//the CSS definitions to your CSS file and use the <? include… line in your
//PHP file wherever you want the news to be displayed.
?>

table.sn {border-width: thin thin thin thin;
border-bottom-spacing: 2px;
border-bottom-color: gray gray gray gray;
border-bottom-style: solid solid solid solid;
border-bottom-collapse: collapse;
text-align: center;
empty-cells: show;
background-color: white;
margin-left: auto;
margin-right: auto;
width: 600px}

td.sn-title {font-family: ‘Lucida Console’, Monaco, monospace;
border-top:1px solid gray;
text-align:left;
border-bottom-width: thin thin thin thin;
padding: 1px 1px 1px 1px;
border-bottom-style: solid solid solid solid;
border-bottom-color: gray gray gray gray;
background-color: white;
color: gray;
border-bottom:1px solid gray;
border-style:dotted;
font-size:16px;
font-weight: bold}
td.sn-date {font-style: italic;
text-align:left;
font-family: sans-serif;
border-bottom-width: thin thin thin thin;
padding: 1px 1px 1px 1px;
border-bottom-style: solid solid solid solid;
border-bottom-color: gray gray gray gray;
background-color: white;
color: black;
font-size:9px}
td.sn-post {font-family: ‘Lucida Console’, Monaco, monospace;
text-align:left;
border-bottom-width: thin thin thin thin;
padding: 1px 1px 1px 1px;
border-bottom-style: solid solid solid solid;
border-bottom-color: gray gray gray gray;
color: black;
font-size:13px;}

<? include("news.txt"); ?> [/php]

You can’t just by using include. You’d have to write another script to parse the news.txt file line by line.

I can’t understand your mean :confused:

ah, now i understand News.txt looks like this:

[php]

Here is title1…
Posted on: 06/02/2012

Here is main text 1…


Here is title2...
Posted on: 06/02/2012

Here is main text 2....


[/php]

By using include(“News.txt”); you’re essentially telling the page to load EVERYTHING in News.txt. What you want to do is read it line by line up till 15 lines have been read.

Sponsor our Newsletter | Privacy Policy | Terms of Service