Solved

Can't find what is wrong with my syntax using an if statement in a query

Posted on 2013-01-13
2
288 Views
Last Modified: 2013-01-13
Can someone see what is wrong with my syntax (it may be completely obvious or for some reason impossible to do. I'm not particularly good at this)

I'm trying to say more or less:
if the Session variable: switch_user_id has a value, use it, otherwise use the session variable user_id value instead. Below is part of a constructed query using datatables.net.

$sWhere .= " AND subscribers.account_id=".
if (isset($_SESSION['switch_user_id']))
{ 
$_SESSION['switch_user_id'];
} else { 
$_SESSION['user_id'];
};

Open in new window


I am using session_start(); at the top of my page.
Get this error in my logs:
PHP Parse error: syntax error, unexpected T_IF
0
Comment
Question by:tjyoung
2 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 38772838
$id=(isset($_SESSION['switch_user_id'])) ? $_SESSION['switch_user_id'] : $_SESSION['user_id'];
$sWhere .= " AND subscribers.account_id=".$id;


Cd&
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 38772854
much nicer. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

21 Experts available now in Live!

Get 1:1 Help Now