我有一个变量$text = "sometexthere"
我想在以下mysql查询中添加此变量$text
而不是sometexthere
$query = "SELECT sum(nbr) AS sum FROM table2 WHERE name LIKE '%sometexthere%'";
我尝试过很多方式,比如
$query = "SELECT sum(stats) AS sum FROM download WHERE filename LIKE '%' . $text . '%'";
和
$name = "'%' . $text . '%'";
$query = 'SELECT sum(stats) AS sum FROM download WHERE filename LIKE '.$name.'';
但不工作:/
答案 0 :(得分:1)
尝试
$query = "SELECT sum(stats) AS sum FROM download WHERE filename LIKE '%$text%'";
并避免这一行
$name = "'%' . $text . '%'";
或尝试这样,
$name = "%".$text."%";
$query = "SELECT sum(stats) AS sum FROM download WHERE filename LIKE '$name'";
答案 1 :(得分:0)
尝试
$query = "SELECT sum(stats) AS sum FROM download WHERE filename LIKE '%" . $text . "%'";