Jump to content

Archived

This topic is now archived and is closed to further replies.

cowboysdude

[SOLVED] A little help with some code please...

Recommended Posts

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! 

Share this post


Link to post
Share on other sites

foreach($filename as $key=>$filename){

    if($filename != $filename){

 

 

 

You're defining the variable $filename twice.

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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)){

}

 

Share this post


Link to post
Share on other sites

LOL Thank you!! I just figured it out.. I got it all working but I DO appreciate all of your guys help!!!!!!!  ;D

Share this post


Link to post
Share on other sites

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.';

}

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.