-2

查询有问题:

$outputs = rosy, rosmary; //array1

$filenames =2.2, 3.2; // array 2

询问:

$insert_col  = "UPDATE `lil` SET `D`='" .$output. "' WHERE `A`= '" .$filename. "'";// does not work

当我给出单个值时,它工作得很好,而不是数组,比如:

$insert_col  = "UPDATE `lil` SET `D`='rosy' WHERE `A`= '2.2'"; // it works

为了将两个数组放入查询中,我编写了 foreach 循环,如下所示

foreach (array_combine($outputs, $filenames) as $output => $filename) {
    $insert_col = "UPDATE `4` SET `D`='" . $output . "' WHERE `A`= '" . $filename . "'";
    echo $insert_col;
}

请帮忙 !!

4

3 回答 3

0
$insert_col = 'UPDATE 4 SET D = CASE A';
foreach($arr as $output => $filename)
{
$insert_col .= 'WHEN ' . $output . ' THEN ' . $filename;
$insert_col .= ' END';
$insert_result= mysql_query($insert_col)or die("Query failed: " . mysql_error());

dint work @eli

于 2013-05-11T08:31:52.267 回答
0

尝试使用 for 循环。获取数组的大小并为该次数运行 for 循环

于 2013-05-11T07:24:51.410 回答
0

尝试

$query = 'UPDATE lil SET D = CASE A';

foreach($arr as $k => $v)
    $query .= 'WHEN ' . $k . ' THEN ' . $v;

$query .= ' END';
于 2013-05-11T07:31:23.937 回答