PHP if exists help

I have the following code that displays .jpg files for records in a database.  This works great except in the case where the _01.jpg file does not exist where is displays the ugly default missing graphic outline in the browser.  Can someone update this snippet so that I can see how to make it only display if the file exists?


if(mysql_num_rows($info) > 0){
			while($row = mysql_fetch_row($info)){
				$cat .= "<tr><td colspan='2' style='background-color:#000000' height='3'><td></tr>";
				$link = "$row[0]";
				$image = "<img width='400' height='300' src='".$datafd[1][$k+1][0]."$row[0].jpg' align='left' vspace='3' hspace='3' /><BR><img width='400' height='300' src='".$datafd[1][$k+1][0]."$row[0]_01.jpg' align='left' vspace='3' hspace='3' />";
				$pas = 1;
				$firstline = "";
				for ($i=0;$i<count($datafd[3][0]);$i++){
					$firstline .= "<td width='$width%'>";
					if (!(strcmp(trim($datafd[3][$k+1][$i]),"no")==0)){
						$firstline .= $row[$pas]."</td>";
						$pas++;
					}
					$firstline .= "</td>";
				}

Open in new window

pda4meAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
try:
if(mysql_num_rows($info) > 0){
                  while($row = mysql_fetch_row($info)){
			   	$f1=$datafd[1][$k+1][0] . $row[0] . '.jpg');
				$f2=$datafd[1][$k+1][0] . $row[0] . '_01.jpg';
			    if( file_exists($f1) && file_exists($f2) )
			    {
                        $cat .= "<tr><td colspan='2' style='background-color:#000000' height='3'><td></tr>";
                        $link = "$row[0]";
                        $image = "<img width='400' height='300' src='".$datafd[1][$k+1][0]."$row[0].jpg' align='left' vspace='3' hspace='3' /><BR><img width='400' height='300' src='".$datafd[1][$k+1][0]."$row[0]_01.jpg' align='left' vspace='3' hspace='3' />";
                        $pas = 1;
                        $firstline = "";
                        for ($i=0;$i<count($datafd[3][0]);$i++){
                              $firstline .= "<td width='$width%'>";
                              if (!(strcmp(trim($datafd[3][$k+1][$i]),"no")==0)){
                                    $firstline .= $row[$pas]."</td>";
                                    $pas++;
                              }
                              $firstline .= "</td>";
                        }
				}
				

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pda4meAuthor Commented:
I swapped out the code and only got a blank white page, no errors?
0
hieloCommented:
do you see the expected values for $f1 and $f2?

...
$f1=$datafd[1][$k+1][0] . $row[0] . '.jpg');
$f2=$datafd[1][$k+1][0] . $row[0] . '_01.jpg';
echo $f1. "<br" . $f2;
 if( file_exists($f1) && file_exists($f2) )
...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.