我收到通知:未定义的变量:我在第23行的C:\ xampp \ htdocs \ search-engine \ search \ search.php
foreach ($terms as $each) {
$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= " OR keywords LIKE '%$each%' ";
}
答案 0 :(得分:1)
你必须定义变量
$i=1;
foreach ($terms as $each) {
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= " OR keywords LIKE '%$each%' ";
$i++;
}
答案 1 :(得分:1)
在使用之前定义i变量值或尝试此
foreach ($terms as $key => $value) {
if ($key == 1)
$query .= "keywords LIKE '%$value%' ";
else
$query .= " OR keywords LIKE '%$value%' ";
}
答案 2 :(得分:0)
首先定义i变量然后像这样使用
$i = 1;
foreach ($terms as $each) {
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= " OR keywords LIKE '%$each%' ";
$i++;
}