Solved

re: if logic in function

Posted on 2009-04-08
5
260 Views
Last Modified: 2012-05-06
i'm not sure where i'm going wrong here

I'm getting this error:
Parse error: syntax error, unexpected T_IF, expecting ';' or '{' in /home/cjehost/public_html/collectors_moment/libraries/joomla/html/html/behavior.php on line 63

thanks!
function caption() 
		if ($_GET['Itemid']=="54"){
			JHTML::script('caption2.js');
		}; else {
			JHTML::script('caption.js');
		};

Open in new window

0
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 250 total points
ID: 24101662
try these
// this should work
 
function caption() 
{
                if ($_GET['Itemid']=="54"){
                        JHTML::script('caption2.js');
                } else {
                        JHTML::script('caption.js');
                };
}
 
 
// this also should work
 
function caption() 
{
                if ($_GET['Itemid']=="54")
                        JHTML::script('caption2.js');
                else
                        JHTML::script('caption.js');
                
}

Open in new window

0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24101722
               }; else {

Indeed, get rid of that cheeky ';'
0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24101731
Sorry, you don't need to have a ';' on closing brackets...
                if ($_GET['Itemid']=="54"){
                        JHTML::script('caption2.js');
                }; else {
                        JHTML::script('caption.js');
                };
 
Should be:
 
                if ($_GET['Itemid']=="54"){
                        JHTML::script('caption2.js');
                } else {
                        JHTML::script('caption.js');
                }

Open in new window

0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24101752
Or... sorry for the repost:

I noticed that you hadn't got the 'caption() {' in your code, you just had 'caption()'
function caption() {
                if ($_GET['Itemid']=="54"){
                        JHTML::script('caption2.js');
                } else {
                        JHTML::script('caption.js');
                }

Open in new window

0
 

Author Closing Comment

by:phillystyle123
ID: 31568253
Thanks Michael701 - this seemed like the most elegant solution:

function caption()
{
                if ($_GET['Itemid']=="54")
                        JHTML::script('caption2.js');
                else
                        JHTML::script('caption.js');
               
}

aside from using too many ';' s - what was i doing wrong?
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question