$brand_condition = ' AND ' . mysql_real_escape_string($brand_selection) . ' IN ';
$brand_condition .= $quote10 . '"'. mysql_real_escape_string($brand_value) . '"' .$quote9;
$brand_conditions[] = $brand_condition;
$query .= implode(' AND ', $brand_conditions) . '';
这产生:AND制造商IN(“brand1,brand2”)
由于我正在使用IN语句,因此我需要引用值。与此同时,我正在使用mysql_real_escape_string转义潜在的引号。
有没有人看到解决这个小问题的简单方法?
答案 0 :(得分:3)
function quote_escape(&$str) {
$str = '"' . mysql_real_escape_string(chop($str)) . '"';
}
$brands = explode(',', $brand_value);
array_walk($brands, "quote_escape");
$brands = implode(',', $brands);
或
function quote_escape($str) {
return '"' . mysql_real_escape_string(chop($str)) . '"';
}
$brands = implode(',', array_map("quote_escape", explode(',', $brand_value)));
答案 1 :(得分:2)
$brand_conditions[] = '"'.$brand_condition.'"';
如何在您在数组中添加brand_condition之前添加引号。
答案 2 :(得分:1)
$concurrent_names = array("O'reilly", 'Tupac "MC New York" Shakur', 'Nemoden');
$escaped_concurrent_names = array_map('mysql_real_escape_string', $concurrent_names);
$condition = 'WHERE name in ("'.implode('", "', $escaped_concurrent_names).'")';
答案 3 :(得分:0)
使用此选项为内爆字符串添加引号。
$ values = implode(“','”,array_values($ values));
答案 4 :(得分:-1)
$brands=array(nokia,samsung,xiomi);
$brands=implode(" ',' ",$brand);
//$brands='nokia','samsung','xiomi';
WHERE column_name IN ($brands)