Jump to content

if true, $var = this image. if false, $var = that image.


RyanSF07

Recommended Posts

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!

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.