
imgrooot
Members-
Posts
383 -
Joined
-
Last visited
-
Days Won
1
Everything posted by imgrooot
-
Is there a better solution to storing this data in mysql table?
imgrooot replied to imgrooot's topic in PHP Coding Help
I didn't know a database could hold billions of rows and still work fine. Good to know. That answers my question. Of course I was giving an extreme example when I said millions of rows. But if it can handle that, then great. I was a little hesitant before because I never had that many records stored in a table before. -
I have a table like this. investment_id | investor_id | deposit | Date | Status I will be depositing funds into this table. For eg. If I am paying out 1000 investors at a time, 1000 rows will be added to this table. I might do this 100 times a day. That's 100,000 rows added in a day. Each deposit I do will be unique, even though it might be going to the same person multiple times. This could end up with million of rows. I am wondering if this is the correct way to do this or is there a better method?
-
Your right. The results for my second and third calculations would be what you wrote. My mistake what I wrote in the comment part of it. But the math works out with the code itself. Your example is an interesting way to solve this problem. And yes now that you mention it, it is more like shares than commissions. I will try it out as well.
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
Alright so I think I have it figured out. It's rather simple. $total_amount = 100; // 100 dollars $total_members = 250; // 250 members $total_commission = 60; // 60% commission $get_percent = ($total_commission / 100) * $total_amount; $new_total = $get_percent / $total_members; // $60 / 250 = 0.24 per user. This is what I was missing before. // Since above is based on 60%, I still have 30% and 10% left. Below are these examples. $total_amount = 100; // 100 dollars $total_members = 50; // 50 members for this example, just to vary it up. $total_commission = 30; // 30% commission $get_percent = ($total_commission / 100) * $total_amount; $new_total = $get_percent / $total_members; // $30 / 250 = 0.12 per user. $total_amount = 100; // 100 dollars $total_members = 20; // 20 members for this example, just to vary it up. $total_commission = 10; // 10% commission $get_percent = ($total_commission / 100) * $total_amount; $new_total = $get_percent / $total_members; // $10 / 250 = 0.04 per user. $60(60%), $30(30%), $10(10%) sum up to $100. No matter how many users are in each percentage pool, it'll always sum up to that exact total.
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
Alright so based on what you said, here is the new example. $total_amount = 100; // 100 dollars $total_members = 250; // 250 members $total_commission = 60; // 60% commission $new_commission = $total_commission / 100; // this would return 0.6 $new_members = 1 / $total_members; // this would return 0.004 $userPercentage = $new_commission * $new_members; // 0.6 * 0.004 = 0.0024 $userShare = $userPercentage * $total_amount; // 0.0024 * 100 = 0.24 $new_total = $userShare * $total_members; // 0.24 x 250 = 60 That returns a total of 60 for each user. That is technically correct. But remember there are total of 250 users. That's $60 x 250 = $15,000. That not what I am looking for. I am looking for all 250 users' amount to sum up to $100 in total. Normally I can 100/250 and it'll return $0.4 for each user. But since each user has a different percentage, each of them is going to have different values that add up to $100. Please let me know if I am making sense.
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
I should also mention that the example I share and the example you edited have are for 3 users only that equals to $100. I will be using this formula in a foreach loop. So if I have more the 4 users, which I do, their total sum is greater than $100, which is not what I want. For eg. Here's the for each loop. $total_members = 250; foreach($result as $row) { $commission = $row['commission']; // This commission could be 10%, 30%, 60%; $amount = $row['amount']; $new_commission = $commission / 100; $userPercentage = 0.1 * $new_commission; $total = $amount; $userShare = $userPercentage * $total; $new_total = $userShare * $total_members; echo $new_total; }
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
So what if I have 250 users? What would 0.1 look like in this line? Is it 1/10th of 250, which is 25? $userPercentage = 0.1 * 0.6;
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
Actually I realized something. Your method would normally work but not with what I am trying to do. For eg. Say I have 30 users. 10 users get 10% 10 users get 30% 10 users get 60% Total of 30 users with their own percentages. Using your method, it would look like this. $userPercentage = 0.1; // 10% $total = 100; $userShare = $userPercentage * $total; // 0.05 * 100 = 10 $new_total = $userShare * 10; // 10 being the amount of users. This totals $100. $userPercentage = 0.3; // 30% $total = 100; $userShare = $userPercentage * $total; // 0.3 * 100 = 30 $new_total = $userShare * 10; // 10 being the amount of users. This totals $300. $userPercentage = 0.6; // 60% $total = 100; $userShare = $userPercentage * $total; // 0.6 * 100 = 60 $new_total = $userShare * 10; // 10 being the amount of users. This totals $600. All totaling to $1,000 for 30 users. That's not what I want. I want to have all 30 users' total come to the original amount, which is $100, not $1,000.
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
That makes sense. Thank you.
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
My question may be a little confusing so I will give you another example. Above I gave you an example of 5 users only. This could easily be 100 or 1000 users. So If I have 100 users with individual percentage of 5%,10%,15% and the total give away amount is $100, how would you divide the $100 among the 100 users?
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
Say I have 5 users. Each user will receive their payment based on their individual percentage. For eg. User 1: 5% User 2: 10% User 3: 15% User 4: 15% User 5: 5% Now say I have a total of $100. I want to divide the $100 among the 5 users. But the users with higher % will receive a higher amount than the the ones with lower %. How would I calculate this?
- 12 replies
-
- calculation
- multiple
-
(and 3 more)
Tagged with:
-
How to access multiple json arrays with single variable?
imgrooot replied to imgrooot's topic in PHP Coding Help
My code works but so does your code. And I must admit your code is far more simpler and cleaner. I will use your example. Thanks. -
How to access multiple json arrays with single variable?
imgrooot replied to imgrooot's topic in PHP Coding Help
Well since no one else has anything to add. Here's my full answer to the original problem. $api_amount = array(); $api_recp = array(); $api_trans_id = array(); $api_sender_id = array(); foreach($get_address->data->txs as $tx){ $api_amount[] = $tx->amounts_received[0]->amount; $api_recp[] = $tx->amounts_received[0]->recipient; $api_trans_id[] = $tx->txid; $api_sender_id[] = $tx->senders[0]; } $post_transid = $_POST['trans-id']; // example 1 if(in_array($post_transid, $api_trans_id)) { echo 'yes'; } else { echo 'no'; } // example 2 if(in_array('0.00400000', $api_amount)) { echo 'yes'; } else { echo 'no'; } -
How to access multiple json arrays with single variable?
imgrooot replied to imgrooot's topic in PHP Coding Help
I tried it as $api_sender_id[] = $tx->senders[0]; And it seems to work. So far so good. Please let me know if anything I've said is incorrect. -
How to access multiple json arrays with single variable?
imgrooot replied to imgrooot's topic in PHP Coding Help
Alright so I think I figured it out. Using "kicken"'s foreach loop, I need to turn the loop variables into an array and access them outside the loop like this. $api_amount = array(); $api_recp = array(); $api_trans_id = array(); $api_sender_id = array(); foreach($get_address->data->txs as $tx){ $api_amount[] = $tx->amounts_received[0]->amount; $api_recp[] = $tx->amounts_received[0]->recipient; $api_trans_id[] = $tx->txid; $api_sender_id[] = $tx->senders; } $post_transid = $_POST['trans-id']; if(in_array($post_transid, $api_trans_id)) { echo 'yes'; } else { echo 'no'; } if(in_array('0.00400000', $api_amount)) { echo 'yes'; } else { echo 'no'; } The above works. One thing that doesn't work is the "$api_sender_id". I realized why. This is how it looks in json. If you look closley you will notice the value of "senders" is directly after the bracket ([). The others don't have that. So how do I access this "senders" value? status" : "success", "data" : { "network" : "BTC", "txs" : [ { "txid" : "71d9afcc73da63c45674088411460116cfefe324cc7a6f5fcb267d9f584adf73", "from_green_address" : false, "time" : 1496877627, "confirmations" : 3080, "amounts_received" : [ { "recipient" : "4QFaAYB4r8sk7MG3beb7yY4R21t9JrnMwK", "amount" : "0.00200000" } ], "senders" : [ "6EqvPUTwjUuon6c2a6YxBreJtBkkZD5fsp" ], "confidence" : 1.0, "propagated_by_nodes" : null } ] } Edit: Sorry for the shit code paste. It shows in fine in the code editor but it for some reason it shows outside of it after I save it. -
How to access multiple json arrays with single variable?
imgrooot replied to imgrooot's topic in PHP Coding Help
I'm assuming you mean check if it's true or not inside the foreach loop like this? foreach ($get_address->data->txs as $tx){ $api_amount = $tx->amounts_received[0]->amount; $api_recp = $tx->amounts_received[0]->recipient; $api_trans_id = $tx->txid; $api_sender_id = $tx->senders; if($api_trans_id == $_POST['trans-id']) { echo 'Success'; } else { echo 'Fail.'; } } If so then I get the "Fail" error. It's shown repeated multiple times. -
I asked this question before and I did receive the answer I was looking for. But now I realize something. It only works for the first result. Let me explain. I am using this API. https://block.io/api/simple/php $get_address = $block_io->get_transactions(array('type' => 'received', 'addresses' => $my_wallet)); $api_amount = $get_address->data->txs[0]->amounts_received[0]->amount; $api_recp = $get_address->data->txs[0]->amounts_received[0]->recipient; $api_trans_id = $get_address->data->txs[0]->txid; $api_sender_id = $get_address->data->txs[0]->senders; These are variables above i am using to check if something is true or not. For eg. The form below. I want to check if the $api_trans_id matches the the post id I submit below. if($api_trans_id == $_POST['trans-id']) { echo 'Success'; } else { echo 'Fail.'; } <form action="" method="post"> <input type="text" name="trans-id" value="" maxlength="1084" /> <input type="submit" name="submit" value="Submit" /> </form> The above works if the first result in the json array below has the same post id or else it fails. I want to loop through ALL the json arrays and try to match the post id($_POST['trans-id']). Below are the 3 array results to give you an example. The first txid is "41d9afcc73da63c45674088411460116cfefe324cc7a6f5fcb267d9f584adf73". If I submit this same id as the post id in the form, it'll be success full. But if I use the 2nd or 3rd txid below, it will fail. So how can I change this "$api_trans_id = $get_address->data->txs[0]->txid;" so that it looks for all three txid instead of only the first one? { "status" : "success", "data" : { "network" : "BTC", "txs" : [ { "txid" : "41d9afcc73da63c45674088411460116cfefe324cc7a6f5fcb267d9f584adf73", "from_green_address" : false, "time" : 1496877627, "confirmations" : 3080, "amounts_received" : [ { "recipient" : "1QFaAYB4r8sk7MG3beb7yY4R21t9JrnMwK", "amount" : "0.00200000" } ], "senders" : [ "2EqvPUTwjUuon6c2a6YxBreJtBkkZD5fsp" ], "confidence" : 1.0, "propagated_by_nodes" : null }, { "txid" : "2f72d4dd97234937ddf6e8174b17a9a421ba35bbfb6fa40cfeb6ac92db6ce032", "from_green_address" : false, "time" : 1491675979, "confirmations" : 12338, "amounts_received" : [ { "recipient" : "1QFaAYB4r8sk7MG3beb7yY4R21t9JrnMwK", "amount" : "0.00010000" } ], "senders" : [ "3L98MQZKvwNo21fFpY7RJ9HYfYdv62XpYz" ], "confidence" : 1.0, "propagated_by_nodes" : null }, { "txid" : "fce58f0cb1d32c1ed7c27825c41753ce98323771bd931f0a0f99b6294d9ee642", "from_green_address" : false, "time" : 1491672301, "confirmations" : 12341, "amounts_received" : [ { "recipient" : "1QFaAYB4r8sk7MG3beb7yY4R21t9JrnMwK", "amount" : "0.00010000" } ], "senders" : [ "4L98MQZKvwNo21fFpY7RJ9HYfYdv62XpYz" ], "confidence" : 1.0, "propagated_by_nodes" : null }, ] } }
-
I am using a phpmailer to send emails to users. I noticed that it only sends email if I am calling it from a page in a root directory. Say I am sending an email from contact.php and it's inside a sub folder/directory instead of the root, it won't email out. Setup is like this. include_once '../phpmailer/class.phpmailer.php'; $mail = new PHPMailer; $mail->IsSMTP(); // Set mailer to use SMTP $mail->Host = '127.0.01'; // Specify main and backup server $mail->From = 'hello@myemail.com'; $mail->FromName = 'Myname'; $mail->AddAddress($user_email); // Name is optional $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->IsHTML(true); // Set email format to HTML $mail->Subject = 'Your account has been deleted!'; $mail->Body = "Hello {$username},<br><br> We are letting you know that your account has been deleted"; if(!$mail->Send()) { $errors[] = $mail->ErrorInfo; } else { if(empty($errors)) { $db->commit(); $success = 'Email sent.'; } else { $db->rollBack(); } }
-
Say I have directory setup like this. core/ includes/ snippets/ template.php js/ index.php Say in the index.php file, I have a file path like this " include 'snippets/template.php'; ". It works. Or say If I am in template.php and I have a file path like this " include '../index.php'; ". It works as well. I am wondering if there is a more global method to this so I don't have to worry about when to use "../" or not. It becomes hectic if there are a lot of includes and/or links.
-
I see your point. I will sure to relay your concerns to the client.
- 20 replies
-
- encryption
- code
-
(and 3 more)
Tagged with:
-
You're second statement could be one of the ways to achieve this goal.
- 20 replies
-
- encryption
- code
-
(and 3 more)
Tagged with:
-
That's all he's trying to achieve. The output is the encrypted password. He basically wants users to have a complex password that they can use for their social media accounts. For eg. User inputs "johnsmith", the output will be "Rju9f3j5?10w3j81". The user can use this output password to register for say Facebook. The user also knows that if they ever forget the output password but knows the original input, he can go back to the site, input "johnsmith" again and receive the exact same output as before. That's his goal.
- 20 replies
-
- encryption
- code
-
(and 3 more)
Tagged with:
-
Alright so here's the new info. The new encryption will be like a password. User inputs text into a textfield and hits submit. It will return a string of 16 digits with uppercase letter, lowercase letter, a number and a special character. There will be no decryption or saving it in the database. Also the client wants it so that it's not a random string of numbers for the same word. So if the input is "johnsmith", then it will return the same string no matter how many times it has been submitted. Can that be done?
- 20 replies
-
- encryption
- code
-
(and 3 more)
Tagged with:
-
I'm getting the details tomorrow. I'll let you know.
- 20 replies
-
- encryption
- code
-
(and 3 more)
Tagged with: