1.这是我的代码 搜索WHERE 1";
foreach ($terms as $each){
$i++;
if ($i == 0)
$query .= "keywords LIKE '%$each%' ";
else
$query .= "OR keywords LIKE '%$each%' ";
}
//connect
Mysql_connect ("localhost", "root","");
Mysql_select_db("search");
$query = mysql_query($query);
$numrows = mysql_num_rows($query);
if ($numrows > 0) {
While ($row = mysql_fetch_assoc($query)) {
$id = $row ['id'];
$tittle = $row ['tittle'];
$description = $row ['description'];
$keywords = $row ['keywords'];
$link = $row ['link'];
echo "<h2><a href='$link'>$tittle</a></h2>
$description<br /><br />";
//disconnect
mysql_close();
}
}
Else
echo "No results found for \"<b>$k</b>\""
?
答案 0 :(得分:0)
虽然您的问题编写得很糟糕且信息丢失,但问题可能是$i
如果您在$i++
声明之前if
,则永远不会为0。
尝试在$i
语句后添加if
增量。
foreach ($terms as $each){
if ($i == 0){
$query .= "keywords LIKE '%$each%' ";
}else{
$query .= "OR keywords LIKE '%$each%' ";
}
$i++
}