I have a query I need to run and I have 2 problems.
first here is my query:
INSERT INTO `anzie_oscommerce`.`discount_codes` (
`discount_codes_id` ,
`discount_description` ,
`products_id` ,
`categories_id` ,
`manufacturers_id` ,
`excluded_products_id` ,
`customers_id` ,
`orders_total` ,
`order_info` ,
`exclude_specials` ,
`discount_codes` ,
`discount_values` ,
`minimum_order_amount` ,
`expires_date` ,
`number_of_orders` ,
`number_of_use` ,
`number_of_products` ,
`status`
)
VALUES (
'' , 'GALA 2012', '' , '' , '' , '' , '' , '2', '1', '0', substr(md5(uniqid(rand(), true)), 0, 8), 250, '0.0000', '2013-22-06', '0', '1', '0', '1'
);
The first problem is I need to generate the random code which I am trying to do with the uniqid function I took from php but I know that is not possible. Is there a way to do something similar in sql?
The second problem is I need to run this 250 times to generate 250 different discount codes. Is there a quick way to run an sql multiple times?
For the first problem: it depends on the database you’re using. Mysql has a rand() function: https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand
For the second: 250 is not many for a database – just putting it in a php for loop would most likely be fine.