Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Two questions: &action= and News Scripting (http://www.programmingforums.org/showthread.php?t=106)

mrbig06 Jul 3rd, 2004 11:26 AM

First question:
I have created a mail form and was wondering how to get the action to be home2.php?page=mail&action=results. I already have the form as home2.php?page=mail.

Second question:
I have also created a news posting script that saves to a file named home.inc and was wondering how I can get the information to display from newest to oldest, instead of oldest to newest.
The information that is written to home.inc looks like this:

:

$output = '<h2 class=/"margin/">'.$date.'</h2>\n<p class=/"margin/">'.$post_content.'</p>';

Any help is greatly appreciated. Thank you in advance.

kurifu Jul 23rd, 2004 12:55 AM

The easiest method is just to write new data to the front of the file.. which means everytime you want to write to a file, write to a temporary file, copy the old news file the the end of the temp file, then move the temp file to the original file's place.

In your form try using:
<input type="hidden" name="action" value="results">

That is the simplest way to do it, and I am assuming will work for your purposes.. if not come back and be a bit more precise on telling us how you plan on generating that URI ;)

Pizentios Jul 23rd, 2004 10:41 AM

Here's a little diddy, that i whiped up...havn't tested it though.

get you script that inputs the news into the file to seperate the news with a line that contains somthing like ^&.

:

<?PHP

$textfile = "Your/Path/to/file"; //set the path to the file here.
if ($text = @file("textfile")) //Don't display errors on file open
{
    $y = 0; //set the height var. for the array.
    for ($x=0; $x<count($text); $x++)
    {
          $tmp = $text[$x];
          if ($tmp == "^&")
          {
                  //we have a line break
                  $textarr[$y][$x] = $text[$x]; //we will need to have the
                                      //line break later when                                                         
                                      //outputing.
                  $y++;
            }
          else
          {
                //we have text that is still part of a new item.
                $textarr[$y][$x] = $text[$x];
            }
      }
      //Now to output the text
      for ($x=count($text); $x<>0; $x--)
      {
            if ($textarr[$y][$x] == "^&") //we have a line brake.
            {
                  $y--;
            }
            else
            {
                echo $textarr[$y][$x];
            }
      }
}
?>


Anyways, That's how i would do it, but kurifu is right
Quote:

The easiest method is just to write new data to the front of the file.. which means everytime you want to write to a file, write to a temporary file, copy the old news file the the end of the temp file, then move the temp file to the original file's place.

Note i havn't tested this code yet, so it might be right or wrong. Probally got some errors in it. And when your putting the news into your file only make a line brake at the top of your news text that you inputting, otherwise you'll get werid stuff happening when you output the code because of the array.

Good luck and hope my code is right...heh


All times are GMT -5. The time now is 8:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC