Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-13
2
Medium Priority
?
294 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
[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
2 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

721 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