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!

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.