我有这些代码,值是重复的
output: Injury Injury Headache Headache
我希望结果是
伤 头痛我尝试区分,但没有任何反应我会显示一些图片来查看所有
if(!empty($_POST['poscon'])) {
foreach($_POST['poscon'] as $condition) {
$condition=mysqli_real_escape_string($link,$condition);
$p=mysqli_query($link,"Select Distinct PossibleCondition
FROM $tablename where Symptoms1='". $condition ."'");
while($r=mysqli_fetch_array($p))
{
$spec=$r["PossibleCondition"];
if(isset($_POST) && isset($_POST['poscon']) && in_array($spec,$_POST['poscon']))
$strIsChecked='checked="checked"';
else
$strIsChecked=null;
echo '<br><td><input type="checkbox" '.$strIsChecked.' title ="'.$spec.'" name="poscon[]" onclick="javascript: submit()" value ="'.$spec.'"></td>';
答案 0 :(得分:1)
Select Distinct PossibleCondition
只会返回不同的PossibleCondition
值。但是,您正在循环$_POST['poscon']
变量,并在每次迭代时执行查询。
可能 - 而不是循环 - 您可以内爆$_POST['poscon']
var(使用逗号)并将其用作where条件。
编辑:代码示例
if(!empty($_POST['poscon'])) {
$condition=mysqli_real_escape_string($link,implode(",",$_POST['poscon']));
$p=mysqli_query($link,"Select Distinct PossibleCondition
FROM $tablename where Symptoms1 IN (". $condition .")");
while($r=mysqli_fetch_array($p))
{
// etc...