0

I'm checking if Facebook users don't like a page. If so, the code displays the user's name and an invitation message to "Like it"; if not, it displays the "incentive landing page". However, I just get the first part: the code doesn't show the "incentive" when users hit the Like button. The code looks like this:

<?php if(!$like_status): ?> 
    <?php if ($me): ?>
      <div id="name">Hola <?php echo $me['first_name']; ?></div> //Everything works fine.  
    <?php endif; ?>
     // Display graphics... Everything works fine.
<?php else : ?>
     //Page with the incentive... This does not work when the nested if is present.
<?php endif; ?>

If I get rid of the nested if (the one that displays the user's name), everything works fine. Any ideas?

10
  • @Charles Sprayberry : is perfectly fine. @Byktor what is the value of the like_status; Commented Jul 19, 2011 at 3:19
  • LOL @ Charles :) Read this bro: php.net/manual/en/control-structures.alternative-syntax.php Commented Jul 19, 2011 at 3:20
  • 1
    Yes, I got to the alternative syntax. I still say the : should be {}. To me, that looks hideous :) Commented Jul 19, 2011 at 3:21
  • 2
    This is the recommended syntax for PHP when code is placed within HTML syntax in a view in most MVC frameworks. Commented Jul 19, 2011 at 3:23
  • Charles: I tried both Like values: false and true. Commented Jul 19, 2011 at 3:52

2 Answers 2

1

You're missing your semicolon after the endif's

<?php if(!$like_status): ?>   
    <?php if ($me): ?>
      // Display user's name... Everything works fine.  
    <?php endif; ?>
     // Display graphics... Everything works fine.
<?php else: ?>
     //Page with the incentive... This does not work when the nested if is present.
<?php endif; ?>
Sign up to request clarification or add additional context in comments.

5 Comments

I already tried the semicolon after the endif... didn't work. I'll recheck it, just in case, and let you know.... Rechecked it and it didn't work.
I'm guessing there is an error in that code you're not showing us ;) Code works fine, just tested it: $like_status = true; if(empty($like_status)): if(!empty($me)): echo 'name'; endif; echo 'graphics'; else: echo 'incentive'; endif; outputs "incentive"
I added the three critical lines.
No spamimng, @Ibu... I just wanted @AlienWebguy to see the result. I deleted the link a few minutes later.
Thank you everybody. I just rewrote the code no nested if and that solved the problem.
0

In case somebody is facing the same problem, I found the solution: for some reason IE 7-8 doesn't like the variable $me and the call to the API('/me') in the same context. I just changed the name of the variable and everything works fine in FF, Chrome, and IE 7-9.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.