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> Link to comment https://forums.phpfreaks.com/topic/171091-solved-image-tags/ Share on other sites More sharing options...
trq Posted August 20, 2009 Share Posted August 20, 2009 Not with html alone. Link to comment https://forums.phpfreaks.com/topic/171091-solved-image-tags/#findComment-902285 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>"; } Link to comment https://forums.phpfreaks.com/topic/171091-solved-image-tags/#findComment-902286 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" Link to comment https://forums.phpfreaks.com/topic/171091-solved-image-tags/#findComment-902292 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! Link to comment https://forums.phpfreaks.com/topic/171091-solved-image-tags/#findComment-902293 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. Link to comment https://forums.phpfreaks.com/topic/171091-solved-image-tags/#findComment-902297 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! Link to comment https://forums.phpfreaks.com/topic/171091-solved-image-tags/#findComment-902796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.