-2

在 php.ini 中获取相关内容的好方法是什么?我有 $keyword,如果我在 where title LIKE '%$keyword%' 中使用它返回相同。我的方法很简单,例如:

$keywords = 'Most Perfectly Timed Videos EVER';
$rel = mysql_query("select * from media where title LIKE '%$keywords%'")or
die(mysql_error());

我希望最大结果与我的关键字相关。谢谢。

4

1 回答 1

1
$query = "SELECT * FROM media WHERE ";
$keywords = 'Most Perfectly Timed Videos EVER';
$keywords = explode(" ", $keywords);
$where = "";
foreach($keywords as $k => $v)
{
    $where .= "title LIKE '%".$v."%' AND ";
}
$where = substr($where, 0, -5); //deleting the last "AND"

$query .= $where;
$rel = mysql_query($query) or die(mysql_error());

或者,如果您可能想使用“OR”而不是“AND”以获得更好的结果:

foreach($keywords as $k => $v)
{
    $where .= "title LIKE '%".$v."%' OR ";
}
$where = substr($where, 0, -4);
于 2012-07-02T13:06:31.877 回答