This works successfully:

$wallet = $user->wallet;
$upwallet = ($sell_video == 0 && $wallet >= 1 ? 0.5 : 0);    
$db->rawQuery("UPDATE ".T_USERS." SET `wallet` = `wallet`- '".$upwallet."' WHERE `id` = '".$video->user_id."'");

(when the sell_video amount is 0 and the wallet amount >= 1, deduct 0.5 from the wallet). Works successfully.

I'd like guidance to add:
When the sell_video amount is 0 and the wallet amount = 0.5, change/update the sell_video to X.

I tried this, without any successful sell_video change:

if($sell_video === 0 && $wallet === 0.5) {
$sell_video = '1';
}

I'm guessing that 'sell_video' has to be updated in the db. Any example of what that might look like is appreciated.

Any assistance is welcomed.

Recommended Answers

All 3 Replies

In order to update the sell_video value in the database, you will need to use the UPDATE statement in a SQL query. Here is an example of how you can update the sell_video value in the T_USERS table in the database:

$db->rawQuery("UPDATE ".T_USERS." SET `sell_video` = '1' WHERE `id` = '".$video->user_id."' AND `wallet` = 0.5");

This query will update the sell_video value to 1 in the T_USERS table for the user with the id specified in the $video->user_id variable, and only if their wallet value is 0.5.

It is also a good idea to check if the UPDATE query was successful, and handle any potential errors or exceptions that may occur. For example:

try {
    $db->rawQuery("UPDATE ".T_USERS." SET `sell_video` = '1' WHERE `id` = '".$video->user_id."' AND `wallet` = 0.5");
} catch (Exception $e) {
    // Handle the exception, for example by logging it or displaying an error message
}

I hope this helps! Let me know if you have any other questions.

Thanks for that great help.
Using your example, I'm trying another one:

    $wallet = $user->wallet;

        if ($sell_video == 0 && $wallet >= 1) {
        $db->rawQuery("UPDATE ".T_USERS." SET `wallet` = `wallet` - '0.5' WHERE `id` = '".$video->user_id."'");
}

but no success. Success would be (upon a transaction) when sell_video is 0 and the wallet is >= 1 then deduct 0.5 from the wallet.

Any guidance with this is greatly appreciated.

Try this (not tested):

$wallet = $user->wallet;

if ($sell_video == 0 && $wallet >= 1) {
    $db->rawQuery("UPDATE ".T_USERS." SET `wallet` = " . $wallet - 0.5 . " WHERE `id` = '".$video->user_id."'");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.