Bug fix help required

Hi - having an issue with the below code, it keeps returning this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/timminsp/beta.freelance-creator.com/www/search/index.php on line 24 - (below is line 24, I have broken the line up to make it easier to read).

<?php $result = $GLOBALS['db']->query("SELECT p.*, c.category_name, t.title_name FROM " . $GLOBALS['config']['db']['prefix'] . "job_posts p 
		LEFT OUTER JOIN " . $GLOBALS['config']['db']['prefix'] . "categories c ON p.category_id = c.category_id
		LEFT OUTER JOIN " . $GLOBALS['config']['db']['prefix'] . "job_titles t ON p.title = t.title_name
		WHERE 1 = 1" + ($job_title != '' ? " AND p.title = '$job_title'" : '') + 
		($job_type != '' ? " AND p.job_type = '$job_type'" : '') + 
		($job_location != '' ? " AND p.job_location = '$job_location'" : '') + 
		($job_salary != '' ? " AND p.job_salary = '$job_salary'" : '')" 
		ORDER BY p.date_created DESC LIMIT " . ($page - 1) * 15 . ", 15"); ?>

I have looked through that line over and over again but cannot see the issue.

Any help would be greatly appreciated.

Thanks

I’m going to assume you’re concatenating much in javascript and php since you used dot for concatenation at some places and then + sign at other places :slight_smile:

Furicane is right, + is not the concatenation operator in PHP. :stuck_out_tongue:

I’m glad I’m not the only one that gets confused. :lol:

What a tit I am - thanks for that :slight_smile:

It is fun when you do something like $str.replace(‘needle’, haystack); and then you wonder why’s there a php error :smiley:

The heredoc syntax can help make these queries a bit easier to develop and maintain:


  $prefix = $GLOBALS['config']['db']['prefix'];
  $sql = <<<EOT
SELECT p.*, c.category_name, t.title_name 
FROM {$prefix}job_posts p 
LEFT OUTER JOIN {$prefix}categories c ON p.category_id = c.category_id
...
EOT;

Eliminates many of the quoting and concat issues.