Solved

re: if logic in function

Posted on 2009-04-08
5
255 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now