PHP从MySQL中选择行,然后使用类似文本将一列与字符串进行比较

PHP从MySQL中选择行,然后使用类似文本将一列与字符串进行比较,php,mysql,string-comparison,Php,Mysql,String Comparison,我想从用户那里得到一个字符串,然后从我的表中选择*并将用户输入的字符串与我从表中得到的一列整行进行比较。如果他们有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

我想从用户那里得到一个字符串,然后从我的表中选择*并将用户输入的字符串与我从表中得到的一列整行进行比较。如果他们有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()) {
致:

参考文献 "

更新:

更改
$json=json\u编码($tem)
$json+=json_encode($tem)

归功于普泽莫利,但这还不够<代码>$json=json\U编码($tem)
应该是
$json+=json\u encode($tem)太多了,否则每一行都会覆盖上一行的json。Tnx人,它几乎可以工作了。我感谢你的帮助。
while($row = $result->fetch_assoc()) {