Script listing objects more than once

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Script listing objects more than once

Post by toasty2 »

My script that I use for listing the mp3's in a directory is listing many of the files more than once. Here's the code:

Code: Select all

<?
//define the path as relative
$path = "/homepages/21/d155481990/htdocs/server";
//using the opendir function
$dir_handle = @opendir($path) or die("Error, oh noez!");
//echo "Directory Listing of $path<br/>";
//echo "";
//running the while loop
while ($file = readdir($dir_handle)) 
{
   if($file!="." && $file!=".." && $file!="songlist.php" && $file!="song.php" && $file!="music.html" && $file!="songdevlist.php" && $file!="id3.php" && $file!="" && $file!="id3.php" && $file!="artistlisttest.php" && $file!="toastplayer" && $file!=null && $file!=".mp3" && $file!="mp3list.php" && $file!="playsong.php" && $file!="index.php")
$newfile = str_replace(".mp3", "", $file);
      echo "<a href=\"playsong.php?song=$newfile\" target=\"song\">$newfile</a><br/>";
}
//closing the directory
closedir($dir_handle);
?>
It's really annoying to have it display a file 6 times. Why is it doing this, or how can I get it to remove multiple entries of the same content from an array and just leave one?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

as I said in your previous thread on this, you're missing some braces to perform the logic you want.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Thanks, got it fixed.
Post Reply