Help with reducing the value and updating

Thanks again.
If you mean this:

WHERE `id` = '".$video->user_id->wallet."'"

that didn’t succeed.
The seller is identified by the videos table id, (video->user_id), but the seller’s wallet is in the users table users-> wallet. So, I’m not sure if I’m connecting the two properly.

WHERE `id` = '".$video->user_id."'"

Understand?
If $video->user_id represents the sellers id then you are updating the users table WHERE id = '".$video->user_id."'".

Thanks for that, yes I understand. Much appreciated. However, this does not succeed:

//update the 'wallet' of the user who uploaded the video(seller)
			// get the uploader's record
			$up_user_start1 = $db->where('id', $video->user_id)->getOne(T_USERS);

			// add to the seller's balance
			$uploader_account1 = $up_user_start1->wallet;

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

any comments/suggestions are appreciated.

The biggest issue I notice in this query is the space before the single quote. It is adding a space after the number so it wouldn’t match a record, e.g. '12 ' instead of '12'. Notice the difference from the “working” query in POST #12.

Thanks, however this was unsuccessful:

//update the 'wallet' of the user who uploaded the video(seller)
			// get the uploader's record
			$up_user_start1 = $db->where('id', $video->user_id)->getOne(T_USERS);

			// add to the seller's balance
			$uploader_account1 = $up_user_start1->wallet;

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

since “//get the uploader’s record” was earlier in the file as:

$up_user_start = $db->where('id', $video->user_id)->getOne(T_USERS);

I thought that there’s no reason to re-define as I did here:

$up_user_start1 = $db->where('id', $video->user_id)->getOne(T_USERS);

and just tried this (without success);

$uploader_account1 = $up_user_start->wallet;

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

any additional comments/suggestions are welcomed

When developing you need to do your own testing of values by echoing them just like we did for $wallet and then found it missing. SO just for testing, add a test echo right above your update query. If you can’t just do echo then set an $error variable just so we can check values.

$error = "uploader_account1: ".$uploader_account1." - upwallet: ".$upwallet." - USERID: ".$video->user_id;

Do expected values show? Anything missing?
These are the kinds of tests you should be doing when something doesn’t work.

Note I agree that you shouldn’t need to redefine a variable or pass a variable value to a new variable name with the same value.

1 Like

Is it correct to have a space inside the single-quotes for the user id?

"' WHERE `id` = '".$video->user_id." ' ");
                                    ^ here 
2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.