Jump to content

[SOLVED] Alphabetical Link Script problem...


TheLoveableMonty

Recommended Posts

<?php

  $infoFile = file_get_contents("med.dat");
  $categoryFile = file_get_contents("cat.dat");
  $infoSort = explode("\n", $infoFile);
  $categorySort = explode("\n", $categoryFile);
  sort($infoSort);
  sort($categorySort);

  foreach ($categorySort as $categoryDraft){
      $categoryItem = trim($categoryDraft);
      echo "<B>$categoryItem</B><BR>";

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

          if(file_exists($location)) {
              $description = file_get_contents($location);
          }

          if ($category == $categoryItem){
              echo "<B>$title</B><BR>";
              echo "<I>$link - $category</I><BR>";
              echo "$description<BR><BR>";
          }
      }
  }
?>

 

The problem I've got is with the echo "$description" variable. Even though I've got the "if" loop to only print items if the category matches the category for the link to be posted, the description seems to print every time. I think I know the problem - the "category" loop passes through the "info" loop for each category saved. Somehow, the description's printing for the same entry as many times as the description loop loops.

 

See the example.

 

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

 

That article is one file, yet it's repeated twice under both loops somehow.

 

I've racked my brains for two hours and have no idea how to figure this thing out.

 

I'd use an SQL database, but I've zero idea on how to impliment them. I'm esentially trying to translate the remainder of my knowledge on CGI to this project, hence why I'm doing it via flat files.

Link to comment
Share on other sites

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.