maxwel Posted May 23, 2013 Share Posted May 23, 2013 while(false!== ($file = readdir($res))) { if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) { if (($info["extension"] == "mp3") || ($info["extension"] == "wav")) { }else{} } } the problem is that when i put an error msg in the else of the red code part it loops as much as files that are not mp3 or wave type. so how i can stop that from happening? and if i did put it outside it wont read $file variable. or even is it possible to know how to make another variable that can bring results of my search outside the while loop cuz i tried alot of things but didnt work :S Thanks in advance, Maxwel Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/ Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 what, exactly, are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431822 Share on other sites More sharing options...
maxwel Posted May 23, 2013 Author Share Posted May 23, 2013 (edited) i want to simply echo an error msg without this error msg being looped another question please: is it possible to get value of certain value from one server to another by php? Edited May 23, 2013 by maxwel Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431830 Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 so you want to break() out of the loop after the first error? or you want to show the last error message? your other question is too vauge to answer with aything more than "it depends". Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431834 Share on other sites More sharing options...
maxwel Posted May 23, 2013 Author Share Posted May 23, 2013 no i want to keep the loop but not to loop the error msg as its inside the loop, is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431837 Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 if it's inside the loop, it's part of the loop. Although you could use a conditional to set the error only if it is not already set, something like if(... } elseif(!isset($errorMsg)){ $errorMsg = "Your Error Message"; } else{ ... } Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431839 Share on other sites More sharing options...
davidannis Posted May 23, 2013 Share Posted May 23, 2013 (edited) Muddy_funster is right. You can set the error message in the loop and echo the error message after the loop completes: while(false!== ($file = readdir($res))) { if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) { if (($info["extension"] == "mp3") || ($info["extension"] == "wav")) { }elseif(!isset($errorMsg)){ $errorMsg = "Your Error Message"; } } }// now we are out of the loop if (isset($errorMsg)) echo $errorMsg; Edited May 23, 2013 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431840 Share on other sites More sharing options...
maxwel Posted May 23, 2013 Author Share Posted May 23, 2013 (edited) @davidannis & Muddy_funster , Thanks alot that was helpful guys been since morning trying to get a way to grab value of a variable from a remote server, tried require, include, fopen, file_get_contents and still cant make it any idea? Edited May 23, 2013 by maxwel Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431861 Share on other sites More sharing options...
Jessica Posted May 23, 2013 Share Posted May 23, 2013 That's a completely different question, I suggest you make a new thread, with a good title, and a very informative description of your problem. Quote Link to comment https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431862 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.