简体   繁体   English

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

[英]Update Query not updating field in table

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... 请告知...其他2个更新查询正在顺利通过...如果您注意到3个更新上方有一个完整查询在评论中...请拆分以查看在更新中不起作用...我确实做了回应vardump ...在循环外,他们给了我正确的值...但是在循环内,他们给了我11111而不是5 ...例如...不确定我在做什么错....我php非常新(2天?),希望能找到解决方案...

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. 第一种情况将$ct更改$ct 1,因此在SQL查询中其值始终为1,因此该查询似乎无法正常工作。

In any case switch doesn't work like that, you need separate if phrases: 在任何情况下,开关都不能那样工作,您需要单独的if短语:

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. 还要注意,在2到4之间没有$ct

Check for $ct value. 检查$ ct的值。

If $checkwon is not greater than or equal to 1000, $ct value will remain the same db value 如果$ checkwon不大于或等于1000,则$ ct值将保持相同的db值

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

Change your update query 更改您的更新查询

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

Remove ";" 删除";" semicolon from here 从这里分号

对MySQL的值使用单引号

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM