我收到通知:未定义的变量:我在第23行的C:\ xampp \ htdocs \ search-engine \ search \ search.php

时间:2015-10-09 04:04:57

标签: php

我收到通知:未定义的变量:我在第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%' ";

     }

3 个答案:

答案 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++;
     }