我正在尝试使用 PHP 来遍历搜索词并将它们附加到 SQL 字符串中,然后再进行搜索。但是,由于此代码,该页面无法正常工作:
$sql .= "
WHERE Title
LIKE '%$ss[$i]%'";
可以在此处查看此代码的完整上下文:
if(isset($_POST['ss'])){
$ss = $_POST['ss'];
$ss = explode(' ',$ss);
$num_search_terms = count($ss);
$sql = "
SELECT *
FROM CRDRecord";
$i = 0;
while($i <= $num_search_terms){
$ssf=
$sql .= "
WHERE Title
LIKE '%$ss[$i]%'";
$i++;
}
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query( $conn, $sql , $params, $options );
$row_count = sqlsrv_num_rows( $stmt );
if ($row_count === false){
echo "Error in retrieving row count.";
}
else {
$jsonData = '{ "num":"Number of records-'.$row_count.',<br><br> search terms being used- <br>search 1- '.$ss[0].'<br>search2- '.$ss[1].'<BR>Number of search terms detected- '.$num_search_terms.'<br>SQL STRING: '.$sql.'" }';
echo $jsonData;
}
}
我知道我想要做什么,但不知道如何表达。很感谢任何形式的帮助。