Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mysqli = new mysqli('localhost', 'sales_user', '12345678', 'sales_thing');
- if (($com = $mysqli->prepare('select id from salesmen'))
- && $com->execute()
- && $result = $com->get_result())
- while ($row = $result->fetch_row())
- generate_random_rows($row[0]);
- else echo $mysqli->error;
- echo 'done!';
- function generate_random_rows($salesManId) {
- global $mysqli;
- $count = rand(0, 300);
- for ($i = 0; $i < $count; $i++) {
- 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)')) {
- $com->bind_param('i', $salesManId);
- $com->execute();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement