doucheng3811 2015-04-07 00:36
浏览 14
已采纳

需要帮助mysqli准备查询然后php进程然后更新每一行

$query = "SELECT id, noms FROM table ORDER BY id ASC";
$query2 = "UPDATE table SET `noms`=? WHERE `id`=?";
if ($stmt = $link->prepare($query)) {
    $stmt2 = $link->prepare($query2);
    $stmt2->bind_param('si',$noms,$id);
    $stmt->execute();
    mysqli_stmt_bind_result($stmt, $id, $noms);
    while (mysqli_stmt_fetch($stmt)){
        $noms = explode("|", $noms);
        for($i=0;$i<count($noms);$i++){
            $noms[$i]=$i.':'.$noms[$i];
        }
        $noms=implode('|',$noms);
        $stmt2->execute();
    }
}

This is what i want to do but there is a problem with collision between queries. How can i get rid of this?

this is simplified. php treatment is more complex. Not just explode/implode. Can't find a solution on google.

  • 写回答

1条回答 默认 最新

  • duanji9264 2015-04-07 00:55
    关注

    why you using this mysqli_stmt_bind_result($stmt, $id, $noms); ?

    why don't you use this $stmt->bind_result($id, $noms); ?

    Check this code :

    $query = "SELECT id, noms FROM table ORDER BY id ASC";
    $query2 = "UPDATE table SET noms=? WHERE id=?";
    if ($stmt = $link->prepare($query)) {
        $stmt2 = $link->prepare($query2);
        $stmt2->bind_param('si',$noms,$id);
        $stmt->execute();
        $stmt->bind_result($id, $noms);
        while ($stmt->fetch()){
            printf ("%s (%i)
    ", $noms, $id);
            //$stmt2->execute();
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题