Php 注意:第23行中的数组到字符串转换
此处的这一行:Php 注意:第23行中的数组到字符串转换,php,mysql,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 $wher
<?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%` ";
*/
?>
包括
$keywords
变量,该变量是数组,而不是字符串。您可能想在那里使用$keyword
变量。$where.=“`keywords``类似于“%$keyword%”
$keywords
是您的数组$keyword
是foreach循环中的单个关键字您从phpacadmy的视频教程中获得了这个脚本,我建议您将连接源更改为PDO,因为它不安全是的,是的,我仍然是php和mysql的初学者。PDO是什么意思?提前感谢汉克斯和皮尔塞涅克斯,这帮了我的忙那是我的错误^^
$where .="`keywords` LIKE '%$keywords%'";