drccfl9407 2014-07-29 18:40
浏览 51
已采纳

PHP表单 - 一键更新许多行

How can I make update of all showed form lines (no whole table) just by one click?

by this code is made update of only one line of form.

    if(isset($_POST['update'])){

        $UpraveneQuery = "UPDATE uctovnictvo SET meno='$_POST[meno]', datum='$_POST[datum]', obchod='$_POST[obchod]', druh='$_POST[druh]', cena='$_POST[cena]', Poznamka='$_POST[poznamka]' WHERE  uct_id='$_POST[hidden]' ";   //--------------
        mysql_query($UpraveneQuery, $con);
    };

Here are data I work with

    $sql = "SELECT * FROM uctovnictvo WHERE meno IN ('" . implode('\', \'', $option_meno) . "') AND obchod IN ('" . implode('\', \'', $option_obchod) . "') AND druh IN ('" . implode('\', \'', $option_druh) . "') AND  datum BETWEEN '$date_start' AND '$date_end'  ORDER BY $order";                 
    $mojeData = mysql_query($sql,$con) or die($sql."<br/><br/> Chyba 1 je:".mysql_error());//run query a ulozit to premennej

Here you can see form where u can make only one update per line (ulozit zmenu).

    while($zaznam = mysql_fetch_array($mojeData)){
    echo "<form action=index-4.php method=post>";
    echo "<tr>";
    echo "<td>" . "<input type=text name=meno value=" . $zaznam['meno'] . ">" . "</td>";
    echo "<td>" . "<input type=date name=datum value=" . $zaznam['datum'] . ">" . "</td>";
    echo "<td>" . "<input type=text name=obchod value=" . $zaznam['obchod'] . ">" . "</td>";
    echo "<td>" . "<input type=text name=druh value=" . $zaznam['druh'] . ">" . "</td>";
    echo "<td>" . "<input step=any type=number name=cena value=" . $zaznam['cena'] . ">" . "</td>";
    echo "<td>" . "<input type=text name=poznamka value=" . $zaznam['poznamka'] . ">" . "</td>";
    echo "<td>" . "<input type=hidden name=hidden value=" . $zaznam['uct_id'] . ">" . "</td>";
    echo "<td>" . "<input type=text name=hidden value=" . $zaznam['uct_id'] . ">" . "</td>";
    echo "<td>" . "<input type=submit name=update value='ulozit zmenu'" . ">" . "</td>";
    echo "<td>" . "<input type=submit name=zmazat value=zmazat" . ">" . "</td>";
    echo "</tr>";
    echo "</form>";
    }

Thank you

  • 写回答

2条回答 默认 最新

  • dongtan9253 2014-07-30 17:11
    关注

    if this is how the second part should looklike then its not working:

        if(isset($_POST['update'])){
        $i=0;
        while(isset($_POST['meno'][$i]))
        {
            $meno = $_POST['meno'][$i];
            $datum = $_POST['datum'][$i];
            $druh = $_POST['druh'][$i];
            $number = $_POST['number'][$i];
            $poznamka = $_POST['poznamka'][$i];
            /*
            $UpraveneQuery = "UPDATE uctovnictvo SET meno='$_POST[meno]', datum='$_POST[datum]', obchod='$_POST[obchod]', druh='$_POST[druh]', cena='$_POST[cena]', Poznamka='$_POST[poznamka]' WHERE  uct_id='$_POST[hidden]' ";   //--------------
            mysql_query($UpraveneQuery, $con);}
            */
            $UpraveneQuery = "UPDATE uctovnictvo SET meno='$meno', datum='$datum', obchod='$obchod', druh='$druh', cena='$cena', Poznamka='$poznamka' WHERE  uct_id='$_POST[hidden]' ";   //--------------
            mysql_query($UpraveneQuery, $con);} 
        };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里