Solved

re: if logic in function

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…

831 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