PHP Code ignitor

Robert Granlund
Robert Granlund used Ask the Experts™
on
I'm trying to write a query in CodeIgnitor and am a little stuck.

What I want to do is set up a variable.  The variable is either equal to $_GET['var']  or it is equal to anything

So when the query runs it will either thry to match the var in that field or it will return anything from that field if it has an entry or if it is empty.

	if (!empty($_GET['interface'])) {
		$interface = $_GET['interface'];
	} else {
		$interface = ' NULL OR NOT NULL';
	}

$query ->
-> from('exp_channel_data t1') 
	-> where('t1.entry_id', $related_id)
	-> where('t1.field_id_4911', $interface) 

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
So what's the problem?

Author

Commented:
Can I write it that way?
$interface = ' NULL OR NOT NULL';
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
I have no idea.  ' NULL OR NOT NULL' should match everything so it doesn't mean anything.
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Just add the where clause if GET['interface'] is not empty:

$query ->
     -> from('exp_channel_data t1') 
     -> where('t1.entry_id', $related_id);

if (!empty($_GET['interface'])) {
     $query ->where('t1.field_id_4911', $_GET['interface'])
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial