What's new

PHP arrays and such.

Cyberman

Moderator
Moderator
Ok.. I have a script I wrote that's fairly simple a series of news articles that are in a text file are read then formated by the script. I want to reverse the order of the articles as they appear in the news list (IE most resent is the LAST item in the file). The problem is Arrays do not seem to work quite right.

I read the subject date and author into 3 arrays then the new text into a third (with CRLF's). However when I go through the array I get empty elements from the array.

Some of the data grabing code...
Code:
function showarticle($NewsH)
{
 $Poster= fgets($NewsH);
 if (!feof($NewsH))
 {
  $Date=   fgets($NewsH);
  if (!feof($NewsH))
  {
   $Title=  fgets($NewsH);
   if (!feof($NewsH))
   {
    showhead($Poster, $Date, $Title);
    echo "<tr><td valign=\"top\">\r\n";
    $Titles[] = $Title;
    $Authors[]= $Poster;
    $Dates[] =  $Date;

disgorging the data..
Code:
 echo "<center>\r\n";
 echo " <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" valign=\"top\" width=\"95%\">\r\n";
 for($Index = $Count-1; $Index > -1; $Index--)
 {
  showhead(
   $Authors[$Index],
   $Dates[$Index],
   $Subject[$Index]
   );
  echo "  <tr><td valign=\"top\">\r\n";
  printf("%d<br>\r\n", $Index);
  echo $Texts[$Index];
  echo "  </tr></td>\r\n";
 }
 */
 echo " </table>\r\n";
 echo "</center>\r\n";

This produces nothing but empty articles, however outputing things in the order they are read in works <if not looks ugly>. OK I need to fix the formating issues as the html put out isn't quite right.

What is my main idiocy here? :) What am I doing wrong?

Cyb
 
Last edited:

The Khan Artist

Warrior for God
Hmm... I don't see anything wrong with that. The first part is definately putting the data into the array.

My only guess would be scope problems. Could you post your entire script along with a data file?
 

zAlbee

Keeper of The Iron Tail
yeah, it might be a scope problem. it doesn't look like you set your array objects to be accessible globally. ie. something like this:

PHP:
function showarticle($NewsH)
{
  global $Titles;
  global $Authors;
  global $Dates;
though i haven't seen the whole thing, so this might not be the problem.
 

Top