Hi everyone

I'm getting a bit confused with a SQL call which pulls up results for a search on a client CMS - basically the client has a list of products which can either be "live" or "recycled" - recycled being temporary deleted and should NOT show up in search results.

I have a function which triggers when the search form is posted, which happens upon keyup. My SQL call in this function is as follows ('kw' being the keyword typed in the search by the client):

$data_sql = "
	CONCAT(u.first_name, ' ', u.last_name) AS user
	FROM products AS p
	INNER JOIN users AS u ON p.modified_by=u.id  
	WHERE p.status='live' AND p.status NOT IN ('recycled') ";
	if($kw) {
		$data_sql .= " AND (p.name LIKE '%" . mysql_real_escape_string($kw) . "%') ";
	if($categories_id != 0) {
		$data_sql .= " AND p.id IN (SELECT products_id FROM products_categories_pivot WHERE categories_id = " . intval($categories_id) . ")";
	$data_sql .= " ORDER BY p.position ASC";
	$data_rs = mysql_query($data_sql);
If the client hits return the results come back fine, but the AJAX call upon keyup returns all products, live or recycled. I even printed out the SQL to the screen on keyup and ran it direct in the database - it returns the correct results.

Can anyone shed any light on this? It's doing my head in because I cannot see why the AJAX method of posting would pull up different results....

Unfortunately I cannot give a link to the CMS as it is password protected for the client only, but I'm hoping you get the idea.

Thanks in advance