我有一個查詢我需要運行,我有2個問題。如何生成隨機代碼,並多次運行sql
首先這裏是我的查詢:
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'
);
第一個問題是我需要生成我正努力與uniqid功能我從PHP走上做隨機碼,但我知道這是不可能的。有沒有辦法在SQL中做類似的事情?
第二個問題是我需要運行這250次才能生成250個不同的折扣代碼。有多種方法可以多次運行sql嗎?
你是在尋找一個隨機的ID或只是唯一的?也就是說,你是否擔心有人能夠從另一個代碼猜測代碼? – JohnFx
我認爲隨機以及獨特。因爲你說的代碼不應該容易被猜到。我認爲我包含在sql語句中的php代碼完全是這樣。 – Sackling