0

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...

3
  • 2
    Why do three separate update queries instead of updating all 3 fields in one query? Commented Aug 27, 2013 at 4:56
  • echo $ct value before passing it to DB. Commented Aug 27, 2013 at 5:07
  • There is a commented out query right above them doing all that Barmar...I commented it and split to see where the problem could be. Commented Aug 27, 2013 at 5:12

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This was it! Can't believe my mistake ! the '=' to '=='...haha...better laugh than cry...accepted. Thanks mate
0

Check for $ct value.

If $checkwon is not greater than or equal to 1000, $ct value will remain the same db value

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

1 Comment

there is no difference in this query both are same
-1

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

2 Comments

What's the difference between your query and OP's query?
@YogeshSuthar you can also see what is the deifference between my query and OP query..?
-1

use single quotes for values of MySQL

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

1 Comment

This didn't solve the issue...why are 2 of my 3 queries passing and the other one is not ??? Exact same syntax...same db attribute characteristics as $checkwon...but still resfusing to work...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.