I'm back scratching my head with PDO and how best to handle queries when they start to get a little more complicated. I'm currently transitioning my queries to PDO.

Currently in the query below I'm using a switch statement to determine the WHERE clause to use (the example below has not been modified for use with PDO). If I try to use the switch variables below with PDO it escapes the values the query comes back empty. Which I get. The query is a mix and match on what values are needed based on category.

What might be my options here? I found PDO::quote in the manual, but it's not really recommended. Am I not seeing the obvious?

switch ($catId) {
	case '1' :
		$selection = "(products_gender = 'U' OR products_gender = 'M') AND (products_category = '2' OR products_category = '1') AND (products_coid = '$myid' AND products_status = 'A')";
		break;

case '2' :
	$selection = "(products_gender = 'U' OR products_gender = 'F') AND (products_category = '2' OR products_category = '1') AND (products_coid = '$myid' AND products_status = 'A')";
	break;

case '3' :
	$selection = "(products_size = '11') AND (products_category = '3') AND (products_coid = '$myid' AND products_status = 'A')";
	break;

case '4' :
	$selection = "(products_size = '11') AND (products_category = '4') AND (products_coid = '$myid' AND products_status = 'A')";
	break;

case '5' :
	$selection = "(products_size = '11') AND (products_category = '5') AND (products_coid = '$myid' AND products_status = 'A')";
	break;

case '6' :
	$selection = "(products_saleitem = 'T') AND (products_coid = '$myid' AND products_status = 'A')";
	break;
}

$query = "SELECT products_id, products_category, products_gender, products_size, products_name, products_price, products_saleitem, products_saleprice, products_inventory, SUM(products_inventory) AS 'totalInv', category_name
		  FROM products
		  LEFT JOIN category
		  ON products.products_category = category.category_id
		  WHERE $selection
		  GROUP BY products_name
		  ORDER BY products_category";
$result = mysql_query($query);

    Write a Reply...