-2
<?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%` ";
*/

?>
4

1 回答 1

3

这一行在这里:

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

包括$keywords变量,它是一个数组,而不是一个字符串。您可能打算在$keyword那里使用该变量。

于 2013-05-05T13:50:18.863 回答