使用PHP一次更新多个SQL记录

时间:2016-10-28 20:16:30

标签: php mysqli

我有一个页面可以将多个记录加载到表单中。我希望能够一次更新多个记录。我在这里尝试了几个解决方案,通常最终只生成一个数组,并没有成功分解所述数组插入sql。任何意见都将非常感谢!

$formresults = $mysqli->query("THIS QUERY LOADS THE FORMS");
    if($formresults){
        while($row = $formresults->fetch_object())
        {
            $a += 1;
            echo "<b>Record Number ".$a."</b><br>";
            echo "<table><input type='hidden' name='Barcode[]' value='".$row->Barcode."' />";
                    echo "<tr><td>Full Name (First Last):</td><td><input type='text' name='Person_Name[]' size='50' value='".$row->Person_Name."' /></td></tr>";
                    echo "<tr><td>Phone Number:</td><td><input type='text' name='Phone[]' size='50' value='".$row->Phone."' /></td></tr>";
                    echo "<tr><td>Address:</td><td><input type='text' name='Address1[]' size='50' value='".$row->Address1."' /></td></tr>";
                    echo "<tr><td>City, State Zip:</td><td><input type='text' name='City[]' size='23' value='".$row->City."' />, <input type='text' name='State[]' size='6' value='".$row->State."' /> <input type='text' name='Zip[]' size='8' value='".$row->Zip."' /></td></tr>";
                    echo "</table><br><br>";

        }
        }

        echo "<button type='submit' name='submit' value='UPDATE'/>";

if(isset($_POST['submit'])){
    if(!isset($_POST['Barcode']) || count($_POST['id']) == 0){
        return;
    }
    foreach($_POST['Barcode'] as $key => $Barcode){
        $update = $mysqli->query("UPDATE table SET     Person_Name='{$_POST['Person_Name'][$key]}' WHERE Barcode='{$Barcode}'");

        if($update){
        echo "It worked";
    }
    }

1 个答案:

答案 0 :(得分:0)

对不起我是个白痴 - 发现我的错误 - 那是我生命中的6个小时撞在桌子上。

if(!isset($_POST['Barcode']) || count($_POST['Barcode']) == 0){

应该是

while IFS= read -r line; do
    parse_output_of_the_line
    echo "${progress}"
done < <(process --with-params | tr '\r' '\n') 
相关问题