RyanSF07 Posted August 16, 2011 Share Posted August 16, 2011 I'm freaking on this... I'm trying to say with this code: if the user is logged in, $favorite = this_image. else, $favorite = that_image. Then later do, $fav = "$favorite"; / echo "$fav" in the template. The problem I'm having is that two images are displayed. Two if logged in. Two if logged out. Can you help me get this working right? if ($session_userid === true) { $favorite = "<a href = \"this_page.php?favorite_id=$get_id\" onClick=\"return confirm('you sure message');\"><img src='images/favorite_button.gif' alt='favorite button' width='90' height='40' border='0'></a>"; }else{ $favorite = "<img src='images/favorite_button_not-logged-in.gif' alt='log in to favorite this page' width='90' height='40' border='0'>"; } $fav = <<<EOD $favorite EOD; The $fav variable is echoed in the template. Thanks! Link to comment https://forums.phpfreaks.com/topic/244936-if-true-var-this-image-if-false-var-that-image/ Share on other sites More sharing options...
Psycho Posted August 16, 2011 Share Posted August 16, 2011 Why do you need $favorite and $fav? It seems all you are doing is defining $fav to be the exact same value as $favorite with some added line breaks. Just use $favorite in your template or use the if/else to define $fav. But, looking at the code provided, I see no reason why you would get two images. The problem is elsewhere. Do you possibly have both $favorite and $fav in your template? Link to comment https://forums.phpfreaks.com/topic/244936-if-true-var-this-image-if-false-var-that-image/#findComment-1258171 Share on other sites More sharing options...
RyanSF07 Posted August 16, 2011 Author Share Posted August 16, 2011 That helped, Mjdamato. Thank you. I got it working now. Link to comment https://forums.phpfreaks.com/topic/244936-if-true-var-this-image-if-false-var-that-image/#findComment-1258185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.