在数据库表中的多个ID处更新一个值

时间:2016-03-14 18:33:48

标签: php mysql arrays database

$upload_files=implode(' ',$_GET['upload_files']);
$upload_user=",".$_GET['upload_user'];
echo $upload_files;
$sql = "UPDATE {$db_pr}files SET userID = CONCAT(userID,'".$upload_user."') WHERE id IN ('".$upload_files."')";

2 个答案:

答案 0 :(得分:0)

IN采用逗号分隔的字符串我相信。

尝试:

$upload_files=implode("','",$_GET['upload_files']);

答案 1 :(得分:-1)

Well, I got the solution. I used for loop to achieve the result. 

$upload_files=$_GET['upload_files'];
$upload_user=",".$_GET['upload_user'];
for ($i = 0, $count = count($upload_files); $i <= $count; $i++) {
$sql = "UPDATE {$db_pr}files SET userID = CONCAT(userID,'".$upload_user."') WHERE id = '".$upload_files[$i]."'";
$result = mysqli_query($mysqli,$sql) or die("Error occurred - tried  to update file.");

}
echo "<div class='loginMessage loginSuccess'>Assigned Successfully!!!</div>";