Jump to content

imgrooot

Members
  • Posts

    383
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by imgrooot

  1. Wow that's a wonderful example. I just have one question. Why use (10,2) instead of say (12,2)? Wouldn't it be safer to use a higher threshold if you're expecting bigger to store bigger numbers?
  2. Say I have two functions that convert from Dollar to Cents and Cents to Dollar. function convertToDollar($value) { $amount = $value / 100; return $amount; } function convertToCents($value) { $amount = $value * 100; return $amount; } Currently I convert all the Dollar amounts to cents and store the cents in the mysql database column. When I showcase those amounts on a page, I simply convert the Cents back to Dollar. Am I doing this correctly or is there a better way to store product pricing in mysql table?
  3. Thanks for backing me up. The 100k emails per day is an extreme example I gave. I just want to make sure that a platform I build is able to accommodate that kind of numbers if ever need be and that I'm using the right service to accomplish it. This is merely sending email notifications to registered users, nothing else.
  4. Could you please give me an example of a good service that provides the API? I've used https://www.sender.net to send bulk emails before. But this is using an email list. And it doesn't seem like they have an API.
  5. Say I am using a normal web hosting company like Namecheap. I have a cron job set to send emails to 100,000 users each day, what would be the best way to deliver those emails the fastest? I know there are other platforms that allows you to send mass emails. But those you have to manually input the email list. I want it automated running from the cron job.
  6. So based on what you said, here's the full query. $find_likes = $db->prepare("SELECT COUNT(*) as likes FROM products p JOIN product_likes pl USING (product_id) WHERE p.user_id = :user_id"); $find_likes->bindParam(':user_id', $my_user_id); $find_likes->execute(); $get_likes = $find_likes->fetchColumn(); echo $get_likes; Seems to work fine now. Thanks.
  7. It's late and I'm not thinking straight. I'm posting this question. Hopefully I get a reply in the morning. I have two tables. TABLE 1 - PRODUCTS TABLE 2 - LIKES I am a User who has posted these products. I want to find out ALL the Likes I have received for all my products. Here is my code. $find_products = $db->prepare("SELECT product_id FROM products WHERE user_id = :user_id"); $find_products->bindParam(':user_id', $my_user_id); $find_products->execute(); $result_products = $find_products->fetchAll(PDO::FETCH_ASSOC); if(count($result_products) > 0) { foreach($result_products as $row) { $product_id = $row['product_id']; $find_likes = $db->prepare("SELECT like_id FROM product_likes WHERE product_id = :product_id"); $find_likes->bindParam(':product_id', $product_id); $find_likes->execute(); $result_likes = $find_likes->fetchAll(PDO::FETCH_ASSOC); if(count($result_likes) > 0) { $get_likes = 0; foreach($result_likes as $row) { $get_likes++; } } } } The issue with the above code is that It only shows the Likes if I echo inside the foreach loop. And it'll show combined Likes from each of my products. But I want to actually combine ALL the Likes from ALL the products and be able show them as a single number, outside of the foreach loop. How do I do that?
  8. Tried your way and it didn't work. Tried it this way and it works. $diff->format("%a days");
  9. So this is a simple code that finds out the difference between two dates and displays it in number of days. $date1=date_create("2013-03-15"); $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2); echo $diff->format("%R%a days"); // RESULT +272 days My first question. Is it possible to remove the + sign in the result above? Second question. Is it possible to show "months" if it's greater than 30 days? And years if the days are greater than 365? How would I do this?
  10. Not sure what you mean. But here is another version of the code. This seems to work fine. $contest_id = 5; $category_id = 8; $find_entries = $db->prepare("SELECT entry_id, user_id, votes FROM contest_entries WHERE contest_id = :contest_id AND category_id = :category_id AND e_status = :e_status AND votes > :votes ORDER BY votes DESC LIMIT 1"); $find_entries->bindParam(':contest_id', $contest_id); $find_entries->bindParam(':category_id', $category_id); $find_entries->bindValue(':e_status', 0); $find_entries->bindValue(':votes', 0); $find_entries->execute(); $result_entries = $find_entries->fetchAll(PDO::FETCH_ASSOC); if(count($result_entries) > 0) { foreach($result_entries as $row) { $entry_id = $row['entry_id']; $user_id = $row['user_id']; $votes = $row['votes']; } echo $entry_id; } else { echo 'nothing'; }
  11. The issue I'm having is that this query won't find a max value record if it has less than 5 votes. It'll only show the results of an entry has 5 or greater votes. Why is that? $contest_id = 5; $category_id = 8; $find_entries = $db->prepare("SELECT entry_id, user_id, votes FROM contest_entries WHERE contest_id = :contest_id AND category_id = :category_id AND e_status = :e_status AND votes = (SELECT MAX(votes) FROM contest_entries) LIMIT 1"); $find_entries->bindParam(':contest_id', $contest_id); $find_entries->bindParam(':category_id', $category_id); $find_entries->bindValue(':e_status', 0); $find_entries->execute(); $result_entries = $find_entries->fetchAll(PDO::FETCH_ASSOC); if(count($result_entries) > 0) { foreach($result_entries as $row) { $entry_id = $row['entry_id']; $user_id = $row['user_id']; $votes = $row['votes']; } echo $entry_id; } else { echo 'nothing'; }
  12. Correct, the multiplication would do the reverse. Like this. function convertToSatoshi($value) { $SAT = $value * 100000000 ; return $SAT; } I was more worried about reversing the decimal part of the 2nd function, but I just realized that it's not needed to convert to Satoshie.
  13. Apparently it's bad to use floats when working with bitcoin. But the API i'm using doesn't really give an option to convert Bitcoin to Satoshie or vice versa. https://www.block.io/api/simple/php So I'm trying to figure out a way to do that function with PHP. Here is the code I found that converts from Satoshie to Bitcoin. My question is, how do I convert from Bitcoin to Satoshie. function convertToBTCFromSatoshi($value) { $BTC = $value / 100000000 ; return $BTC; } function formatBTC($value) { $value = sprintf('%.8f', $value); $value = rtrim($value, '0') . ' BTC'; return $value; } echo formatBTC(convertToBTCFromSatoshi(5000));
  14. I was wondering if there is a way to automatically get a user's timezone? I want to show certain information if the user's current date is less than the expiry date. It works fine if the user is in a default timezone but what if the user is in a different timezone? How I can I make sure I can get their correct current time? date_default_timezone_set('America/New_York'); $expiry_date = trim($row['expiry_date']); $current_date = date('Y-m-d H:i:s'); if($current_date < $expiry_date) { // show data } else { // don't show }
  15. Oh wow, it works. That was simple. Thank you.
  16. My mistake. I am using this api and used their output because it was cleaner looking.https://block.io/api/simple/php But same as above, if I print_r the variable like this. $newInfo = $block_io->get_current_price(array()); print_r($newInfo); It will give me the output like this. object(stdClass)#5 (2) { ["status"]=> string(7) "success" ["data"]=> object(stdClass)#6 (2) { ["network"]=> string(3) "BTC" ["prices"]=> array(11) { [0]=> object(stdClass)#7 (4) { ["price"]=> string(6) "1590.0" ["price_base"]=> string(3) "AUD" ["exchange"]=> string( "coinspot" ["time"]=> int(1488981211) } [1]=> object(stdClass)#8 (4) { ["price"]=> string( "1201.203" ["price_base"]=> string(3) "USD" ["exchange"]=> string(5) "btc-e" ["time"]=> int(1488981211) } [2]=> object(stdClass)#9 (4) { ["price"]=> string(10) "1149.95741" ["price_base"]=> string(3) "EUR" ["exchange"]=> string(5) "btc-e" ["time"]=> int(1488981211) } [3]=> object(stdClass)#10 (4) { ["price"]=> string(7) "68920.0" ["price_base"]=> string(3) "RUR" ["exchange"]=> string(5) "btc-e" ["time"]=> int(1488981211) } [4]=> object(stdClass)#11 (4) { ["price"]=> string(7) "1203.14" ["price_base"]=> string(3) "USD" ["exchange"]=> string( "coinbase" ["time"]=> int(1488981213) } [5]=> object(stdClass)#12 (4) { ["price"]=> string(6) "1205.9" ["price_base"]=> string(3) "USD" ["exchange"]=> string( "bitfinex" ["time"]=> int(1488981214) } [6]=> object(stdClass)#13 (4) { ["price"]=> string(6) "1202.0" ["price_base"]=> string(3) "EUR" ["exchange"]=> string(7) "litebit" ["time"]=> int(1488981222) } [7]=> object(stdClass)#14 (4) { ["price"]=> string(7) "1206.61" ["price_base"]=> string(3) "USD" ["exchange"]=> string( "bitstamp" ["time"]=> int(1488981224) } [8]=> object(stdClass)#15 (4) { ["price"]=> string(6) "1154.2" ["price_base"]=> string(3) "EUR" ["exchange"]=> string( "bitstamp" ["time"]=> int(1488981224) } [9]=> object(stdClass)#16 (4) { ["price"]=> string(6) "8037.0" ["price_base"]=> string(3) "CNY" ["exchange"]=> string(4) "bter" ["time"]=> int(1488981225) } [10]=> object(stdClass)#17 (4) { ["price"]=> string(6) "7830.0" ["price_base"]=> string(3) "CNY" ["exchange"]=> string( "btcchina" ["time"]=> int(1488981208) } } } } Using your json_decode like this doesn't work. It doesn't return me anything. No error either. $variable = json_decode($newInfo); echo $variable->status;
  17. Say I have this array. $block_io->get_current_price(array()); That array will give me this output. { "status" : "success", "data" : { "network" : "BTC", "prices" : [ { "price" : "1500.01", "price_base" : "AUD", "exchange" : "coinspot", "time" : 1488955012 }, { How can I convert the above output into individual variables? For eg. $status = 'success'; $network = 'BTC'; $price = '1500.01'; ...etc
  18. I see your example. Here's the updated query. My question is, how do I convert the $row array into actual singular variables? Also where did "$products" come from? $stmt = $db->prepare("SELECT user_id, filled_positions FROM matrix_2"); if ($stmt->execute()) { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $products[$row['user_id']][] = $row; $products[$row['filled_positions']][] = $row; print_r($row); } }
  19. Say I have a table with 100 users. I want to retrieve those 100 users with each of them having unique variable name. What's the proper way to do that? I know I can create 100 different queries and retrieve them like this. But what's a better solution? $find_sponsor_2 = $db->prepare("SELECT user_id, filled_positions FROM matrix_2 WHERE user_id = :user_id"); $find_sponsor_2->bindValue(':user_id', 2); $find_sponsor_2->execute(); $result_sponsor_2 = $find_sponsor_2->fetchAll(PDO::FETCH_ASSOC); if(count($result_sponsor_2) > 0) { foreach($result_sponsor_2 as $row) { $matrix_user_id_2 = $row['user_id']; $filled_positions_2 = $row['filled_positions']; } } else { $errors[] = 'User Id 2 not found in Matrix.'; } $find_sponsor_3 = $db->prepare("SELECT user_id, filled_positions FROM matrix_2 WHERE user_id = :user_id"); $find_sponsor_3->bindValue(':user_id', 3); $find_sponsor_3->execute(); $result_sponsor_3 = $find_sponsor_3->fetchAll(PDO::FETCH_ASSOC); if(count($result_sponsor_3) > 0) { foreach($result_sponsor_3 as $row) { $matrix_user_id_3 = $row['user_id']; $filled_positions_3 = $row['filled_positions']; } } else { $errors[] = 'User Id 3 not found in Matrix.'; } $find_sponsor_4 = $db->prepare("SELECT user_id, filled_positions FROM matrix_2 WHERE user_id = :user_id"); $find_sponsor_4->bindValue(':user_id', 4); $find_sponsor_4->execute(); $result_sponsor_4 = $find_sponsor_4->fetchAll(PDO::FETCH_ASSOC); if(count($result_sponsor_4) > 0) { foreach($result_sponsor_4 as $row) { $matrix_user_id_4 = $row['user_id']; $filled_positions_4 = $row['filled_positions']; } } else { $errors[] = 'User Id 4 not found in Matrix.'; Someone mentioned I could do it like this. But my question is, how do I get unique variables for each user, such as "$matrix_user_id_2, $matrix_user_id_3, $matrix_user_id_4" as shown in my code above. $find_sponsor = $db->prepare("SELECT user_id, filled_positions FROM matrix_2 WHERE user_id in (2,3,4)"); $find_sponsor>execute(); $result_sponsor = $find_sponsor->fetchAll(PDO::FETCH_ASSOC); print_r($result_sponsor);
  20. Awesome. I will give it shot. Thanks.
  21. It seems like I haven't explained my situation properly. 1. To put it simply, I want to loop through "matrix" table. 2. Find all the rows that have user id. 3. Get all the columns from the row with the lowest user id. 4. Do if else statement to see if each of the 14 positions in said row are empty. If they are not, insert the new users until they are filled. 5. Move on to the next row with the next highest user id. Do the same thing as above. Rinse and repeat. Here's a query example I have so far. $find_sponsor = $db->prepare("SELECT * FROM matrix WHERE user_id > :user_id"); $find_sponsor->bindValue(':user_id',0); $find_sponsor->execute(); $result_sponsor = $find_sponsor->fetchAll(PDO::FETCH_ASSOC); if(count($result_sponsor) > 0) { foreach($result_sponsor as $row) { $sponsor_id = $row['sponsor_id']; $user_id = $row['user_id']; $filled_positions = $row['filled_positions']; $position_1 = $row['position_1']; $position_2 = $row['position_2']; $position_3 = $row['position_3']; $position_4 = $row['position_4']; $position_5 = $row['position_5']; $position_6 = $row['position_6']; $position_7 = $row['position_7']; $position_8 = $row['position_8']; $position_9 = $row['position_9']; $position_10 = $row['position_10']; $position_11 = $row['position_11']; $position_12 = $row['position_12']; $position_13 = $row['position_13']; $position_14 = $row['position_14']; } if(empty($position_1)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_1 = :position_1, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_1', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_2)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_2 = :position_2, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_2', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_3)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_3 = :position_3, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_3', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_4)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_4 = :position_4, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_4', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_5)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_5 = :position_5, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_5', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_6)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_6 = :position_6, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_6', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_7)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_7 = :position_7, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_7', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_) { $update_sponsor = $db->prepare("UPDATE matrix SET position_8 = :position_8, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_8', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_9)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_9 = :position_9, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_9', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_10)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_10 = :position_10, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_10', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_11)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_11 = :position_11, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_11', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_12)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_12 = :position_12, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_12', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_13)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_13 = :position_13, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_13', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else if(empty($position_14)) { $update_sponsor = $db->prepare("UPDATE matrix SET position_14 = :position_14, filled_positions = :filled_positions + 1 WHERE user_id = :user_id"); $update_sponsor->bindParam(':position_14', $new_user_id); $update_sponsor->bindParam(':filled_positions', $filled_positions); $update_sponsor->bindParam(':user_id', $matrix_user_id); if($update_sponsor->execute()) {} } else {} }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.