0

実行する必要のあるクエリがあり、2つの問題があります。

最初に私の質問があります:

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'
);

最初の問題は、phpから取得したuniqid関数で実行しようとしているランダムコードを生成する必要があることですが、それは不可能です。SQLで同様のことを行う方法はありますか?

2番目の問題は、これを250回実行して、250の異なる割引コードを生成する必要があることです。SQLを複数回実行する簡単な方法はありますか?

4

2 に答える 2

1

最初の問題: 使用しているデータベースによって異なります。Mysql には rand() 関数があります: https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand

2 つ目: 250 はデータベースには多くありません。php の for ループに入れるだけで十分でしょう。

于 2012-11-05T04:25:48.393 に答える
0

ソノファグンの答えが好きです。もう 1 つのトリックは、ダミー テーブルから 250 回選択することです。

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`
)
(select '' ,  'GALA 2012', '' , '' , '' , '' , '' ,  '2',  '1',  '0',  substr(md5(uniqid(rand(), true)), 0, 8),  250,  '0.0000',  '2013-22-06',  '0',  '1',  '0',  '1' union all
select '' ,  'GALA 2012', '' , '' , '' , '' , '' ,  '2',  '1',  '0',  substr(md5(uniqid(rand(), true)), 0, 8),  250,  '0.0000',  '2013-22-06',  '0',  '1',  '0',  '1' union all
select '' ,  'GALA 2012', '' , '' , '' , '' , '' ,  '2',  '1',  '0',  substr(md5(uniqid(rand(), true)), 0, 8),  250,  '0.0000',  '2013-22-06',  '0',  '1',  '0',  '1' union all
select '' ,  'GALA 2012', '' , '' , '' , '' , '' ,  '2',  '1',  '0',  substr(md5(uniqid(rand(), true)), 0, 8),  250,  '0.0000',  '2013-22-06',  '0',  '1',  '0',  '1' union all
...however many times
);
于 2012-11-05T05:05:40.777 に答える