I have plans to write an unique PHP news script without using a database. I need to figure a way to allow comments.

++ Plans ++

addnews.php
I will be able to add News Title, Short Description, and News body. After I submit the news data, I want it to INSERT into a news.db file in this format:
["News ID", "News Title", "Brief Description", "News Body", "Date", "Author"]
So an example would be:
["1", "Site has launched!", "Get the scoop on the site launch!", "The body of the news will go here and it will allow html but not php. I could go on forever in the body but will it mess up the news.db?", "January 15, 2004", "Ps2gamer"]
Each news would be in a [].

viewnews.php
I want to be able to read the news that is in the news.db. And on the page I want it to show in this format:

<a href="shownews.php?id=(News ID)">(News Title)</a><br>(Brief Description)<br>Posted On: (Date) by: (Author)<br><br>

shownews.php
Pritty much the same format as viewnews.php except instead of Brief Description it would be the full body and shownews.php will only show 1 news item and it gets it from the URL (shownews.php?id=1). I alos would need to have a comment link {eg. comments.php?id=(News ID)}

addcomments.php
I need for people to add comments for a paticular news item and have it store it into comments.db using this format:
["News ID", "Comment ID", "Comment Title", "Comment Body", "Date", "Author", "Email"]

comments.php
I need for people to view all the comments underneath the actualy body of the news body (in the same format as shownews.php). But like this underneath everything:

[CODE]

Posted on: (Date) by: <a href="(Email)">(Author)</a><br>

(Comment Body)<br>

[/CODE]

editnews.php + deletenews.php
I also need to be able to edit each and every news item, including ID,title, body and date. And of course if I can edit it, then I will need to be able to delete them. I also need to be able to edit and delete comments according to News ID or Comment ID.

I am an ok php programmer, but I am not familar with file stuff, So if anyone can lead me into the right direction about how I can accomplish this that would be great.

    You'll be working with flatfiles. It's really simple.
    When you create the news.db, you'll have your information as an array and each line will contain the data for a specific new.

    Then you can parse to variables the array for each line ($news_id,$news_title,$description,$body,$date,$author).

    The best solution for your comments, depends of your needs. But I would create another file (comments.db or something like this). You need to create an identifier for each news and so you can associate it with the comments.

    I think if you want to create your own whole script, you'd have a look at some scripts (there are a lot in the web). Because there are different ways to do that. I self have built 2 and both are totally different.

      Is there anyway you can show some of your code to get me started or point me to a php script that uses this. I tried looking at cutenews and fusionnews but their scripting is way to complicated for me to comprehend.

        Ok, let me play a little around it.

        You'll need a form to create all the data for each news.
        enterdata.html (Could be .php or the same script).

        <form name="form1" method="post" action="your_script.php">
        <table width="442" border="1" cellpadding="2" cellspacing="2">
        <tr><td>News Id</td>
        <td><input name="news_id" type="text" id="news_id"></td></tr>
        <tr><td>News Title</td>
        <td><input name="news_title" type="text" id="news_title"></td></tr>
        <tr><td>Description</td>
        <td><textarea name="description" id="description"></textarea></td></tr>
        <tr><td>Body</td>
        <td><textarea name="textarea"></textarea></td></tr>
        <tr><td>Date</td>
        <td><input name="date" type="text" id="date"></td></tr>
        <tr><td>Author</td>
        <td><input name="author" type="text" id="author"></td></tr>
        <tr><td>&nbsp;</td>
        <td><input type="submit" name="Submit" value="Submit"></td></tr>
        </table></form>

        your_script.php

        $news_id = $_POST['news_id];
        $news_title = $_POST['news_title];
        //and so on for each one....
        
        $new_news = "$news_id<|<$news_title<|<$description<|<etc......\n";
        // If your news.db is ready then...
        $db = "news.db";
        $fp = fopen($db,"a");
        fputs($fp,$new_news);
        fclose($fp);
        
        

        This way you have it stored.

        In your shownews.php you need.....

        $wanted_id = $_GET['id'];
        $news_db = "news.db";
        $file = file($news_db);
        foreach($file as $v) {
        list($news_id,$news_title,$description,$body,$date,$author) = explode("<|<",$v);
        if($wanted_id==$news_id) {
        $my_title = $news_title;
        $my_text = $body;
        // All the data you need
        }
        

        Then you put these variables where you want them.

        For the comments you may do it the same way. Just you wont need to use the if() statement, cause you want to show all of them.

          Thank you, i wil play around with it

          and if i have any more questions i will post it

            Write a Reply...