Jump to content

Recommended Posts

function getPosts() {
// Variables for category and information file locations.
  $infoURL = "med.dat";
  $categoryURL = "cat.dat";

// Open both files and store information to variables.
  $infoFile = file_get_contents($infoURL);
  $categoryFile = file_get_contents($categoryURL);

// Turn variables to arrays by splitting strings by page breaks.
  $infoSort = explode("\n", $infoFile);
  $categorySort = explode("\n", $categoryFile);

// Arrange information and categories in alphabetical order.
  sort($infoSort);
  sort($categorySort);

// THE FOLLOWING HAS BEEN HELD BACK TO BE DEBUGGED...
//
// Rewrite file with organised information. This is to cut down on the time
// taken for the loops to compare values for display.
//  $infoSave = fopen($infoURL, a);
//
//  foreach ($infoSort as $infoWrite){
//      $infoWrite = "$infoWrite\n";
//      fwrite($infoSave, $infoWrite);
//      echo "Written \"$infoWrite\"...<BR>";
//  }
//
//  fclose($infoSave);
//
// Also do the same thing with category information, to ensure no new entries
// have slipped out of order.
//  $categorySave = fopen($categoryURL, w);
//
//  foreach ($categorySort as $categoryWrite){
//      $categoryWrite = "$categoryWrite\n";
//      fwrite($categorySave, $categoryWrite);
//  }
//
//  fclose($categorySave);

// Starts loop to compare each category to information.
  foreach ($categorySort as $categoryDraft){
      $categoryItem = trim($categoryDraft);
      echo "<TR>\n";
      echo "  <TD BGCOLOR=\"#2A338D\" VALIGN=\"top\">\n";
      echo "      <FONT FACE=\"trebuchet ms\" COLOR=\"#F3B809\" SIZE=\"3\"><B>$categoryItem</B></FONT><BR>\n";
      echo "      <FONT FACE=\"trebuchet ms\" COLOR=\"#FFFFFF\" SIZE=\"2\">";

// Starts loop to display content information alphabetically.
      foreach ($infoSort as $infoDraft){
          $infoLines = explode("#~#", $infoDraft);
          $title       = $infoLines[1];
          $link        = $infoLines[2];
          $category    = trim($infoLines[0]);
          $location    = "desc/".$infoLines[3].".dat";

// Checks to see if description's available and sets $description accordingly.
          if(file_exists($location)) {
              $description = file_get_contents($location);
          }

// Print page items if $info category matches current $category value.
          if ($category == $categoryItem){
              $categoryCheck == true;
              echo "<FONT COLOR=\"#F3B809\"><B>$title</B></FONT> - ";
              echo "<I><A HREF=\"".$link."\">".$link."</A><BR>\n";

// This piece is more required for the Directory section, so we'll leave
// it for later...
//            echo "$description<BR><BR>";
          }

// Reset description - otherwise, previous description will continue to load if
// current description is unavailable.
//        $description = "";


          echo "  </TD>\n";
          echo "</TR>\n";

// HELD DUE TO BUG IN SAVING SYSTEM
// This instance has been rendered useless and will halt the comparison
// process early, as other category contents may be listed further down
// the information file.
//
// Break loop if category's already loaded - saves time comparing.
//          if ($categoryCheck == true && $category != $categoryItem){
//             break;
//          }
      }
  }
}

 

Above is the code for a script to display links in a directory in categories. The script uses flat files as opposed to a database as I'm unable to use PHP to manipulate information in an SQL database.

 

The problem I'm facing is the loops keep displaying "blank" entries. I added a rewrite code to rewrite the source files in alphabetical order in order to save time on loading the script, but the code keeps writing blank lines which ultimately lead to more blank links and categories being printed.

 

Can anyone help me? This is literally the last headache I face on this damn thing, as everything else seems to be in order.

 

A sample can be viewed here:

 

http://www.tenthousandbillboards.com/inf-bin/med/media.php.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/143896-basic-content-display-issue/
Share on other sites

Yeah, the file exists on my server. The problem simply is the unexplained breaks forming in the med.dat and cat.dat files causing blank entries to be displayed and subsequently saved.

 

I haven't got the foggiest why it's happening, although I believe it relates to the way I compare if articles are of a specific subject.

 

Honestly, I've confused myself. This is the third damn query on the script I've been trying to write, but it's also the last one. I can't find any other forseen problems occuring with this script.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.