SkyRanger Posted June 19, 2006 Share Posted June 19, 2006 Here is the situation:I use to have a piece of code from along time ago that did this for me, but I lost it, can can't remember how I did it.This is what I need:mysql garbageif $image exists echo '$image'if $image does not exist then echo "No Image"Can anybody help me with this? Link to comment https://forums.phpfreaks.com/topic/12349-if-there-or-not-there/ Share on other sites More sharing options...
SkyRanger Posted June 19, 2006 Author Share Posted June 19, 2006 [!--quoteo(post=385510:date=Jun 18 2006, 11:44 PM:name=SkyRanger)--][div class=\'quotetop\']QUOTE(SkyRanger @ Jun 18 2006, 11:44 PM) [snapback]385510[/snapback][/div][div class=\'quotemain\'][!--quotec--]Here is the situation:I use to have a piece of code from along time ago that did this for me, but I lost it, can can't remember how I did it.This is what I need:mysql garbageif $image exists echo '$image'if $image does not exist then echo "No Image"Can anybody help me with this?[/quote]Nevermind, found what I was looking for:[code=php:0]echo "<img src=image/" . ($row['image'] == 'Yes' ? "$image" : "No Image") . "' />";[/code] Link to comment https://forums.phpfreaks.com/topic/12349-if-there-or-not-there/#findComment-47193 Share on other sites More sharing options...
SkyRanger Posted June 19, 2006 Author Share Posted June 19, 2006 [!--quoteo(post=385515:date=Jun 18 2006, 11:56 PM:name=SkyRanger)--][div class=\'quotetop\']QUOTE(SkyRanger @ Jun 18 2006, 11:56 PM) [snapback]385515[/snapback][/div][div class=\'quotemain\'][!--quotec--]Nevermind, found what I was looking for:[code=php:0]echo "<img src=image/" . ($row['image'] == 'Yes' ? "$image" : "No Image") . "' />";[/code][/quote]Ok, thought I had it but I am getting this error:Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/low/public_html/roster.phtml on line 167This is the code I have:[code]<? echo "<img src='" . ($row['image'] == 'Yes' ? $image"/>View Image</a>" : "No Image") . "'"; ?>[/code] Link to comment https://forums.phpfreaks.com/topic/12349-if-there-or-not-there/#findComment-47199 Share on other sites More sharing options...
.josh Posted June 19, 2006 Share Posted June 19, 2006 umm..[code]if ($row['image']) { echo "<img src = '" . $row['image'] . "' />";} else { echo "no image";}[/code] Link to comment https://forums.phpfreaks.com/topic/12349-if-there-or-not-there/#findComment-47204 Share on other sites More sharing options...
SkyRanger Posted June 19, 2006 Author Share Posted June 19, 2006 [!--quoteo(post=385526:date=Jun 19 2006, 12:36 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 19 2006, 12:36 AM) [snapback]385526[/snapback][/div][div class=\'quotemain\'][!--quotec--]umm..[code]if ($row['image']) { echo "<img src = '" . $row['image'] . "' />";} else { echo "no image";}[/code][/quote]Awsome, thanks, exactly what I needed Link to comment https://forums.phpfreaks.com/topic/12349-if-there-or-not-there/#findComment-47330 Share on other sites More sharing options...
poirot Posted June 19, 2006 Share Posted June 19, 2006 Or use the ternary operator correctly:[code]echo ($row['image']) ? '<img src="' . $row['image'] . '"/>' : 'No Image';[/code] Link to comment https://forums.phpfreaks.com/topic/12349-if-there-or-not-there/#findComment-47337 Share on other sites More sharing options...
.josh Posted June 19, 2006 Share Posted June 19, 2006 or yeah that too, but i figured it would be better to use a code he'd probably understand better :\ Link to comment https://forums.phpfreaks.com/topic/12349-if-there-or-not-there/#findComment-47355 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.