TheLoveableMonty Posted February 5, 2009 Share Posted February 5, 2009 <?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. Quote Link to comment Share on other sites More sharing options...
TheLoveableMonty Posted February 5, 2009 Author Share Posted February 5, 2009 All I had to do was reset the $description variable at the end of each loop. I wish it wasn't 4am - otherwise I might be able to think. Meh... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.