cowboysdude Posted March 8, 2009 Share Posted March 8, 2009 This is what I have... but I also have a problem. When there is no file it is still a clickable link... I do not want that. I just want it to be empty with no clickable areas... currently if you click on it, it will tell you that NO SUCH file exists... lol I knew that ... how do I make it so nothing happens if there is no file.. <?php $filename= array($fileone,$filetwo,$filethree,$filefour,$filefive,$filesix,$fileseven,$fileeight); $title= array($name1,$name2,$name3,$name4,$name5,$name6,$name7,$name8); $time= array($time1,$time2,$time3,$time4,$time5,$time6,$time7,$time8); $path = $params->get('path'); foreach($filename as $key=>$filename){ if($filename != $filename){ echo " "; }else{ echo "<a href='$path/$filename'> $title[$key] <br /> $time[$key]"; } } ?> Somebody gave me this suggestion.. use; if(!empty($filename){ } BUT I have tried to replace this line with the above if($filename != $filename){ echo " "; } But I get a parsing error.. Suggestions? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
corbin Posted March 8, 2009 Share Posted March 8, 2009 foreach($filename as $key=>$filename){ if($filename != $filename){ You're defining the variable $filename twice. Quote Link to comment Share on other sites More sharing options...
cowboysdude Posted March 8, 2009 Author Share Posted March 8, 2009 foreach($filename as $key=>$filename){ if($filename != $filename){ You're defining the variable $filename twice. Well ok... lol being very green at this I'm not sure I'm reading it like this: foreach FILE print the title plus time, if the file does not equal the file then do something. I may be wrong and why I can't figure this out..WHEW... this learning stuff ... The first line defines the file plus the title and time so it will show up in html... is that wrong? Thank you Quote Link to comment Share on other sites More sharing options...
corbin Posted March 8, 2009 Share Posted March 8, 2009 What's wrong though is that you're looping through the array $filename and defining the values to $filename. You don't see the problem? After the first iteration, $filename will no longer be your array; it will be the first name from the $filename array. Quote Link to comment Share on other sites More sharing options...
fabrydesign Posted March 8, 2009 Share Posted March 8, 2009 Somebody gave me this suggestion.. use; if(!empty($filename){ } BUT I have tried to replace this line with the above if($filename != $filename){ echo " "; } But I get a parsing error.. Missing a parentheses... if(!empty($filename)){ } Quote Link to comment Share on other sites More sharing options...
cowboysdude Posted March 9, 2009 Author Share Posted March 9, 2009 LOL Thank you!! I just figured it out.. I got it all working but I DO appreciate all of your guys help!!!!!!! Quote Link to comment Share on other sites More sharing options...
alphanumetrix Posted March 12, 2009 Share Posted March 12, 2009 simple. if you don't want an error, try this: if (!empty($yourfilevar)) { // your code to execute... } if you want to display your own error, do this: if (!empty($yourfilevar)) { // your code to execute... } else { echo 'There was no file.'; } 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.