How to get unique id from array implode when passing value through multiple selection php

时间:2015-09-29 00:44:18

标签: php arrays postdata

How to get each value unique id from array implode when passing value through multiple selection php? When I pass single data, I can get the id; while when I pass multiple data it won't shown any id.

I have some ideas, is it the problem when select more that 2 values while post to next page; it will combine the data "ROBERT ALVIN" so the database could not catch the data; How do I split the data to "ROBERT" "ALVIN", so I would able to get the id "1" "2".

when select single data!

http://b62i.imgup.net/33ba8c.png

when select two or more data!

http://v58i.imgup.net/1232cde.png

Sample coding.

$myselected     =   $_POST["auditor"];
$auditor = implode (" ",$myselected);

$query10 = "SELECT * FROM auditor WHERE auditor_name = '$auditor' ";
$result10 = $db->query($query10);
$row10 = $result10->fetch_array();

<tr>
<td><b>Auditor:</b></td>

<td colspan='5'>
<?php 
echo'<input type="text" name="form_details_id" value="'.$row10["id"].'">';

    foreach ($myselected as $auditor){ 
    echo $auditor."<br>\n"; 
    }
?>
</td>

1 个答案:

答案 0 :(得分:0)

要匹配多个值,您可以使用mysql IN子句。您使用implode

在引号中创建值的字符串
$myselected     =   $_POST["auditor"];

if(count($myselected)>1){
$auditor = implode ("','",$myselected);
}else
$auditor =$myselected;
}

$query10 = "SELECT * FROM auditor WHERE auditor_name IN ('$auditor') ";

其余的就像你上面一样。您需要在上面的

中添加用户输入卫生设施