doujue6196 2013-08-27 04:51
浏览 23
已采纳

更新查询不更新表中的字段

I am currently struggling with the following :

$res = $db->uniquequery("SELECT distinct won_current,ctt,darkmatter FROM ".USERS."     WHERE `id` = '".$USER['id']."'");

$checkwon = $res['won_current'];
$ct=$res['ctt']; 
$dm=$res['darkmatter'];

These appear to be working. Now...

$dmgift=0;
while($checkwon>=1000)
{
    $ct=$ct+1;                       
    //incrementing $ct doesnt seem to work in  the loop but it works fine outside it                                         
    $checkwon=$checkwon-1000;

    //threshold ranges and setting of dmgift.
    switch($ct){
        case $ct=1 : $dmgift=25000;break;
        case $ct>=5 && $ct<10: $dmgift=50000;break;
        case $ct>=10 && $ct<15: $dmgift=75000;break;
        case $ct>=15 && $ct<20: $dmgift=100000;break;
        case $ct>=20 : $dmgift=150000;break;

    }
    $dm=$dm+$dmgift;

    //$db->query("UPDATE ".USERS." SET won_current=$checkwon,ctt=$checkthreshold,darkmatter=$dm WHERE `id` = ".$USER['id'].";");
$db->query("UPDATE ".USERS." SET won_current=$checkwon WHERE `id` = ".$USER['id'].";");
$db->query("UPDATE ".USERS." SET ctt='$ct' WHERE `id` = ".$USER['id'].";"); // this update query is not passing.db field remains the same

$db->query("UPDATE ".USERS." SET darkmatter=$dm WHERE `id` = ".$USER['id'].";");           


}

Kindly advise...the other 2 update queries are passing well...if you notice above the 3 updates I had a full query commented in...split it to see what is not working in update... I did echo and vardump...outside the loop they gave me the correct values...BUT inside the loop they have me 11111 instead of 5...for example...not sure what I'm doing wrong....I'm very new to php ( 2 days ? ) and would appreciate a solution...

  • 写回答

4条回答 默认 最新

  • donglei2022 2013-08-27 06:47
    关注

    The problem is with the switch.

    switch($ct){
        case $ct=1 : $dmgift=25000;break;
        ...
    }
    

    The first case changes $ct to 1, so its value is always 1 in the SQL query so it looks like the query doesn't work.

    In any case switch doesn't work like that, you need separate if phrases:

    if( $ct == 1 ) { 
        $dmgift=25000
    }
    else if( $ct>=5 && $ct<10 ) {
        $dmgift=50000;
    }
    else if( $ct>=10 && $ct<15 ) {
        $dmgift=75000;
    }
    else if( $ct>=15 && $ct<20 ) {
        $dmgift=100000;
    }
    else if( $ct>=20 ) {
        $dmgift=150000;
    }
    

    Also note that you don't have cases for $ct between 2 and 4.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM