jodan
03-28-2003, 06:46 PM
If a coder can help in any way I would appreciate it. Anyway to the point:
I am trying to write a PHP news script, that functions much like a forum would (as in saving news posts as arrays in files named as ID#'s, etc.). I can call each of the file's contents to print flawlessly in a separate .php file; however, the order it prints the files is "1.php", "2.php", "3.php", and on up (printing the news items in order of oldest post to the most recent post (printed last). I cannot for the life of me reverse the order of printing. I need to print the larger # (ex. 3.php) PRIOR to printing 2.php and so on...
My funtions.php contains the following code:
function getdata($name){
$dataarray=@file($name);
for($n=1;$n<count($dataarray);$n++){$dataarray2[$n-1]=trim($dataarray[$n]);}
return $dataarray2;
}
function show_news()
{
if ($dir = @opendir("posts")) {
$n = 1;
while (($file = readdir($dir)) !== false) {
if ($file == "." || $file == "..") continue;
$postsarray = getdata("posts/$n.php");
print "Author: $postsarray[1]<br>";
print "Subject: $postsarray[2]<br>";
print "Body: $postsarray[3]<br><br>";
$n++;
}
}
@closedir(posts);
}
?>
The function show_news() is called from news.php to (obviously) show the news.
"posts" is the directory that the news files (1.php, 2.php, etc.) are stored.
If I need to further explain anything please let me know, I will do so happilly. Thanks in advance for any help...:thumbsup:
I am trying to write a PHP news script, that functions much like a forum would (as in saving news posts as arrays in files named as ID#'s, etc.). I can call each of the file's contents to print flawlessly in a separate .php file; however, the order it prints the files is "1.php", "2.php", "3.php", and on up (printing the news items in order of oldest post to the most recent post (printed last). I cannot for the life of me reverse the order of printing. I need to print the larger # (ex. 3.php) PRIOR to printing 2.php and so on...
My funtions.php contains the following code:
function getdata($name){
$dataarray=@file($name);
for($n=1;$n<count($dataarray);$n++){$dataarray2[$n-1]=trim($dataarray[$n]);}
return $dataarray2;
}
function show_news()
{
if ($dir = @opendir("posts")) {
$n = 1;
while (($file = readdir($dir)) !== false) {
if ($file == "." || $file == "..") continue;
$postsarray = getdata("posts/$n.php");
print "Author: $postsarray[1]<br>";
print "Subject: $postsarray[2]<br>";
print "Body: $postsarray[3]<br><br>";
$n++;
}
}
@closedir(posts);
}
?>
The function show_news() is called from news.php to (obviously) show the news.
"posts" is the directory that the news files (1.php, 2.php, etc.) are stored.
If I need to further explain anything please let me know, I will do so happilly. Thanks in advance for any help...:thumbsup: