Solved

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

Posted on 2013-01-13
2
286 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

15 Experts available now in Live!

Get 1:1 Help Now