bmdsherman Posted August 20, 2009 Share Posted August 20, 2009 Is there anyway I could do something like this? <img src=something.jpg (if something.jpg doesn't exist): src=something-else.jpg> Quote Link to comment Share on other sites More sharing options...
trq Posted August 20, 2009 Share Posted August 20, 2009 Not with html alone. Quote Link to comment Share on other sites More sharing options...
bmdsherman Posted August 20, 2009 Author Share Posted August 20, 2009 Not with html alone. Hmm, what about with php? The code around the image is: <?php while($row = mysql_fetch_assoc($result)){ echo "<center> <table border='0' cellspacing='2' cols='2' frame='void' rules='none'> <colgroup> <col width='350'> <col width='350'> <col width='350'> </colgroup> <tbody> <tr> <td><center><a href=profile.php?p={$row['id']}>{$row['fname']} {$row['lname']}</a></center></td> <td><center><a href=mailto:{$row['email']}>{$row['email']}</a></center></td> <td><center><img src={$row['img']}></center></td> </tr> </tbody> </table>"; } Quote Link to comment Share on other sites More sharing options...
haku Posted August 20, 2009 Share Posted August 20, 2009 $src = (is_file($row['img'])) ? $row['img']: "somethingelse.jpg"; <td><center><img src={$src}></center></td> You will have to play with that. Also, you should be putting double quotes around your html attributes. So instead of: <img src=something you have <img src="something" Quote Link to comment Share on other sites More sharing options...
bmdsherman Posted August 20, 2009 Author Share Posted August 20, 2009 Also, you should be putting double quotes around your html attributes. So instead of: <img src=something you have <img src="something" Ya I know I'm cheating but I'm using double quotes for the php echo because variables aren't picked up in single quotes. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
haku Posted August 20, 2009 Share Posted August 20, 2009 It's not a problem with cheating, it's a problem that your code won't work properly in some browsers. It also won't be valid. You have a choice, either escape your quotes inside the double quotes: echo "<img src=\"$row['img']\" />"; Or preferably exit out of your quotes and put in the value: echo '<img src="' . $row['img'] . '" />'; The second one being more efficient when processing. Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted August 20, 2009 Share Posted August 20, 2009 You could also use a heredoc. I did some research - and it seems like its almost as efficient as concatenating your strings and variables. Check it out on google! 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.