作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
它显示了几种疾病。我只想根据我输入的内容在数据库中检索最近的疾病。然后,结果是狼疮和麻疹
<?php
include('connect.php');
//Function to sanitize values received from the form. Prevents SQL injection
//Sanitize the POST values
$symptom1 = $_POST['symptom1'];
$symptom2 = $_POST['symptom2'];
$symptom3 = $_POST['symptom3'];
$symptom4 = $_POST['symptom4'];
$sql = mysql_query("SELECT disease FROM diseases WHERE
symptom1 LIKE '%". $symptom1."%' OR symptom1 LIKE '%". $symptom2."%' OR symptom1 LIKE '%". $symptom3."%' OR symptom1 LIKE '%". $symptom4."%' AND
symptom2 LIKE '%". $symptom1."%' OR symptom2 LIKE '%". $symptom2."%' OR symptom2 LIKE '%". $symptom3."%' OR symptom2 LIKE '%". $symptom4."%' AND
symptom3 LIKE '%". $symptom1."%' OR symptom3 LIKE '%". $symptom2."%' OR symptom3 LIKE '%". $symptom3."%' OR symptom3 LIKE '%". $symptom4."%' AND
symptom4 LIKE '%". $symptom1."%' OR symptom4 LIKE '%". $symptom2."%' OR symptom4 LIKE '%". $symptom3."%' OR symptom4 LIKE '%". $symptom4."%'");
while($row = mysql_fetch_array($sql))
{
echo $row['disease'];
}
//end of while loop
?>
最佳答案
$query="
SELECT
disease,
(
symptom1 LIKE '%" . $symptom1 . "%'
OR symptom1 LIKE '%" . $symptom2 . "%'
OR symptom1 LIKE '%" . $symptom3 . "%'
OR symptom1 LIKE '%" . $symptom4 . "%'
) + (
symptom2 LIKE '%" . $symptom1 . "%'
OR symptom2 LIKE '%" . $symptom2 . "%'
OR symptom2 LIKE '%" . $symptom3 . "%'
OR symptom2 LIKE '%" . $symptom4 . "%'
) + (
symptom3 LIKE '%" . $symptom1 . "%'
OR symptom3 LIKE '%" . $symptom2 . "%'
OR symptom3 LIKE '%" . $symptom3 . "%'
OR symptom3 LIKE '%" . $symptom4 . "%'
) + (
symptom4 LIKE '%" . $symptom1 . "%'
OR symptom4 LIKE '%" . $symptom2 . "%'
OR symptom4 LIKE '%" . $symptom3 . "%'
OR symptom4 LIKE '%" . $symptom4 . "%'
) AS `score`
FROM
diseases
HAVING `score` > 0
ORDER BY `score` DESC";
关于php - 如何在MySQL中应用真实度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33115159/
我是一名优秀的程序员,十分优秀!