Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    flat-file cms: make new posts go to the top?

    I need some help with a cms I am making, i cant figure out how to make the old news go down and put the newest news at the top. can anybody help?
    PHP Code:
    <?PHP
    $time 
    date("F jS Y, h:iA");
    $name $_POST["name"];
    $title $_POST["title"];
    $text $_POST["text"];

    $data fopen('show_news2.php'"w+");

    fwrite($data"<center><strong>$title</strong></center><br/>
    $text <br/>
    <center><em>Posted by: $name, on $time</em></center><br/><br/>"
    );
    fclose($data);
    echo 
    'News Updated, <a href="http://tackypenguin.com/index.php">Home page</a>, or go <a href="index.php">Back</a>';
    ?>
    thats what i have so far
    Last edited by RyanRyan; 03-25-2007 at 04:51 AM.

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    $data fopen('show_news2.php'"r+"); 
    w+ Truncates the whole file and starts over. r+ is what your looking for.

  • #3
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i'm sitting right next to him...what he is trying to say is that he wants to make the older posts move down and the new post be placed on top. look at my website: www.flashanims.com do you see how the newest posts are at the top? that is what he wants. and i think r+ just goes to the top and then writes over it.
    ..
    ▲ ▲

  • #4
    New Coder
    Join Date
    Mar 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay i tried it and it wrote from the top, but it wrote over the old news instead of pushing it down so there was only a part of the old news below the new news, the rest was written over

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts

  • #6
    New Coder
    Join Date
    Mar 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There has to be a way. i tried to look over cutenews code to see but i couldnt find any

  • #7
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts
    hmmm.......
    Last edited by Armondo; 03-25-2007 at 05:04 AM.
    ..
    ▲ ▲

  • #8
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok I see that append only writes to the bottom and everything else overwrites. How about this.

    Open the file in 'r' mode.
    Read it and put the contents in a variable.
    Append your new content to the beginning of the read variable
    Write it back to the file.

    See if that works for ya.

  • #9
    New Coder
    Join Date
    Mar 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    like this?
    PHP Code:
    <?PHP
    $time 
    date("F jS Y, h:iA");
    $name $_POST["name"];
    $title $_POST["title"];
    $text $_POST["text"];
    $data2 fopen('show_news2.php',"r");

    $data fopen('show_news2.php'"w");

    fwrite($data"<center><strong>$title</strong></center><br/>
    $text <br/>
    <center><em>Posted by: $name, on $time</em></center><br/><br/>"
    $data2);
    fclose($data);
    fclose($data2);
    echo 
    'News Updated, <a href="http://tackypenguin.com/index.php">Home page</a>, or go <a href="index.php">Back</a>';
    ?>

  • #10
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    $data2 needs to be "read"

    PHP Code:
    $filename "show_news2.php";
    $handle fopen($filename"r");
    $old_contents fread($handlefilesize($filename));

    $new_contents "<center><strong>$title</strong></center><br/>
    $text <br/>
    <center><em>Posted by: $name, on $time</em></center><br/><br/>"
    ;

    $write $new_contents.$old_contents;

    $handle2 fopen($filename"w");
    fwrite($handle2$write);

    //close your opens... and maybe add in some error checking? 

  • #11
    New Coder
    Join Date
    Mar 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, I have been tryin to figure out how to forever THANK YOU. what is your website?

  • #12
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Your welcome. I run quite a few but my personal one is http://www.myarmedforces.com.

    Glad to help enjoy!

  • #13
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts
    yippe ryan you FINALLY GOT THIS WORKING. you don't even want to know how long he has been bugging me about this.
    ..
    ▲ ▲

  • #14
    New Coder
    Join Date
    Mar 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nice site thanks once again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •