注意:第23行中的数组到字符串转换

时间:2013-05-05 13:47:53

标签: php mysql

<?php
include 'db.inc.php';


//function that well return search results
//takes the keywords entered by user

function search_results ($keywords){

    //code here
    $returned_results= array();//array that will contain results
    $where= ""; // constract of query for results

    $keywords = preg_split ('/[\s]+/', $keywords);
         //function split values by space
     // (hello aya) is like ( hello  aya )

    $total_keywords = count($keywords);
         //count number of words entered ex(ayoy adel =2 , a b c s = 4)


    foreach ($keywords as $key=>$keyword){
    $where .="`keywords` LIKE '%$keywords%'";
               if ($key != ($total_keywords -1 )){
                 $where .= " AND " ;
               }

        }

       $results = "SELECT `title` , `subject` , `id` FROM `` WHERE $where ; ";
       }

    //array begins from 0 , this erro

    //$key=>$keyword key=0 , 1, 2   $keyword value in database
    //
    //
    //

    /*$sqlQuery= " SELECT `keywords` FROM `question` WHERE `keywords` LIKE `%hci%` AND  `keywords` LIKE `%what%` ";
*/

?>

1 个答案:

答案 0 :(得分:3)

这一行:

$where .="`keywords` LIKE '%$keywords%'";

包含$keywords变量,它是一个数组,而不是一个字符串。你可能想在那里使用$keyword变量。