Endless Loop Issue

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
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Endless Loop Issue

Post by Bigun »

I attempt to upload and verify an MP3...

Then the loop below never ends

Code: Select all

//Music Uploading goes here
        //Setup loop to check variables
        if ($makechanges == "yes" && $band == "yes") {
                for($i = 0; $i < 10 || $makechanges == "yes"; $i++) {
                        echo $i;
                        $currsongfile = 'songfile' . $i;
                        $currsongname = 'songname' . $i;
                        if ($$currsongname != "" && $$currsongfile != "") {
                                //Song Present - Run Tests
                                // include getID3() library (can be in a different directory if full path is specified)
                                require_once('./getid3/getid3/getid3.php');

                                // Initialize getID3 engine
                                $getID3 = new getID3;

                                // Analyze file and store returned data in $ThisFileInfo
                                $ThisFileInfo = $getID3->analyze($$currsongfile);

                                // Optional: copies data from all subarrays of [tags] into [comments] so
                                // metadata is all available in one location for all tag formats
                                // metainformation is always available under [tags] even if this is not called
                                getid3_lib::CopyTagsToComments($ThisFileInfo);

                                // Output desired information in whatever format you want
                                // Note: all entries in [comments] or [tags] are arrays of strings
                                // See structure.txt for information on what information is available where
                                // or check out the output of /demos/demo.browse.php for a particular file
                                // to see the full detail of what information is returned where in the array
                                $bitrate=@$ThisFileInfo['audio']['bitrate'];           // audio bitrate
                                $time=@$ThisFileInfo['playtime_string'];            // playtime in minutes:seconds, formatted string
                                $format=@$ThisFileInfo['fileformat'];
                                if ($bitrate == "" || $time == "" || $format != "mp3") {
                                        //The file has no valid bitrate or no valid time or isn't an MP3 - reject
                                        $makechages = "no";
                                        echo "<center><font color=red><b>The File uploaded doesn't seem to be a valid MP3 - Rejecting File</b></font></center><br>";
                                }
                        }
                }
}
I'm fairly sure it's this line here:

Code: Select all

for($i = 0; $i < 10 || $makechanges == "yes"; $i++) {
But how else would I exit the loop if an invalid MP3 is found?
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

I see the problem... it should be &&(and) not ||(or).
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

You've also got a typo. This

Code: Select all

$makechages = "no";
should be

Code: Select all

$makechanges = "no";
phpCCore Brad
Forum Commoner
Posts: 47
Joined: Sun Dec 04, 2005 5:46 pm
Location: Michigan, USA
Contact:

Post by phpCCore Brad »

Does the || really make a difference? Aren't both of them valid in PHP?

http://us3.php.net/manual/en/language.o ... ogical.php

Is it possible the script is looping forever for another reason. Very strange that a for next would look forever anyhow, since it has a definite ending point... I mean I could be completely wrong. I always use and and or. Not && and ||
Post Reply