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
https://forums.phpfreaks.com/topic/143880-solved-alphabetical-link-script-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.