Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP Help with getting correct amount into table column

chrisj

Bronze Coder
What I'm trying to accomplish, is that every time an amount gets updated to the uploaders 'balance' column,
half that amount gets updated(added to) into the uploaders 'money' column. However, using the code
below, when the amount '3' is added to the 'balance' column, just '1' gets added to the 'money' column,
instead of the intended amount of 1.5. And both columns have the same table structure:

PHP:
$up_amount = $video_cost_new *0.50;


// add to the balance
$uploader_account = $up_user_start->balance+$up_amount;


$money_amount = $up_amount / 2;
$up_user_start = $db->where('id', $video->user_id)->getOne(T_USERS);
$money_account = $up_user_start->money+$money_amount;
$db->where('id', $video->user_id);
$update_money = $db->update(T_USERS, [
'money' => number_format($money_account, 1, '.', ''), ]);

Can you suggest what I can change to get it correct?
 
Last edited:
What I'm trying to accomplish, is that every time an amount gets updated to the uploaders 'balance' column,
half that amount gets updated(added to) into the uploaders 'money' column. However, using the code
below, when the amount '3' is added to the 'balance' column, just '1' gets added to the 'money' column,
instead of the intended amount of 1.5. And both columns have the same table structure:

PHP:
$up_amount = $video_cost_new *0.50;


// add to the balance
$uploader_account = $up_user_start->balance+$up_amount;


$money_amount = $up_amount / 2;
$up_user_start = $db->where('id', $video->user_id)->getOne(T_USERS);
$money_account = $up_user_start->money+$money_amount;
$db->where('id', $video->user_id);
$update_money = $db->update(T_USERS, [
'money' => number_format($money_account, 1, '.', ''), ]);

Can you suggest what I can change to get it correct?
Is the column in the database an integer column? Does it allow decimals?
Does $db->update treat this money column in the T_USERS table as an integer, or as a double? For example... $db->bind_param("id", $decimal, $decimal); ... this code would turn the first parameter into an integer because the 'i' forces it to, even though the original value is a decimal number. The 'd' on the other hand is a double (floating point number, "float", or any "real number"). It will let you keep the decimal places!
 

New Threads

Buy us a coffee!

Back
Top Bottom