Advertisement
VladislavSavvateev

Untitled

Mar 2nd, 2021
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. $mysqli = new mysqli('localhost', 'sales_user', '12345678', 'sales_thing');
  4.  
  5. if (($com = $mysqli->prepare('select id from salesmen'))
  6. && $com->execute()
  7. && $result = $com->get_result())
  8. while ($row = $result->fetch_row())
  9. generate_random_rows($row[0]);
  10. else echo $mysqli->error;
  11. echo 'done!';
  12.  
  13. function generate_random_rows($salesManId) {
  14. global $mysqli;
  15.  
  16. $count = rand(0, 300);
  17. for ($i = 0; $i < $count; $i++) {
  18. if ($com = $mysqli->prepare('insert into sales(sold_at, salesman_id, product_id, qty) values(date_add(now(), interval round(rand() * 90 * 24 * 60 * 60) second), ?, (select id from products order by rand() limit 1), round(rand() * 2) + 1)')) {
  19. $com->bind_param('i', $salesManId);
  20. $com->execute();
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement