我想从用户那里获取一个字符串,然后从我的表中选择 *,然后将用户输入的字符串与我从表中获得的一列整行进行比较。 如果它们相似 10%,则回显整行。代码是这样的,但它不起作用:
//this String is entered by user
$x = $_GET['x'];
$sql = "SELECT * FROM Products WHERE pro_avail = 1";
$result = $conn->query($sql);
if ($result->num_rows >0) {
while($row[] = $result->fetch_assoc()) {
//compare the 'pro_specs' column to the string that the user has given
$sim = similar_text($row['pro_specs'], $_GET['x'], $perc);
if($perc > 10){
$tem = $row;
$json = json_encode($tem);
}
}}
else {
echo "0 results";
}
echo $json;
$conn->close();
更改:
while($row[] = $result->fetch_assoc()) {
自:
while($row = $result->fetch_assoc()) {
参考http://php.net/manual/en/mysqli-result.fetch-assoc.php'
更新:
将$json = json_encode($tem);
更改为$json += json_encode($tem);
信用przemo_li