2014-05-08 28 views
-2

我可以使用payment_status = rand('pending','success','failed','refunded')进行下面的查询,或者任何人都可以帮助我解决以下查询的错误。我可以使用rand('等待','成功','失败','退款')

for ($i=0;$i<100000;$i++) 
{ 
$payment_status = rand('pending','success','failed','refunded');  
$sql = 'INSERT INTO `aa_kkkk` (`id`, `user_id`, `biz_id`, `filing_year`, `filing_month`, `final_return`, `consent_disclosure`, `is_third_party_designee`, `amended_month`, `earliest_date`, `latest_date`, `tax_year_end_month`, `address_change`, `form_type`, `submission_id`, `payment_status`, `transaction_id`, `active`, `xml_submitted`, `date_user_submitted`, `date_xml_sent`, `date_last_ack_attempt`, `date_acknowledged`, `created_date`, `modified_date`, `next_submission_date`, `irs_approved`, `ack_received`, `sch1_received`, `sch1_path`, `user_completed`, `consent_to_submit`, `error_code`, `error_description`, `error_type`, `modifiedby_admin`, `data_masked`, `form_pdf_path`) VALUES 
(Null, ':user_id', ':biz_id', ':filing_year', "c2aaf5544415889e720f042b04551c97'.$i.'", "c9c396be60e066ae92b978c08a3fca0a'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "0", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "84843320140520033138'.$i.'", ':payment_status', "", ':transaction_id', ':active', "2014-02-21 10:31:35", "2014-02-21 03:31:42", "2014-02-21 03:32:00", "2014-02-21 03:32:00", "2014-02-21 03:11:15", "2014-04-18 11:12:39", NULL, ':irs_approved', ':ack_received', ':sch1_received', "84843320140520033138.pdf'.$i.'", 1, 1, "", "", "", 0, 0, "pf2290_1_84843320140520033138.pdf'.$i.'")'; 
+0

http://www.php.net/manual/en/function.rand.php – PeeHaa

+0

'int rand(int $ min,int $ max)'no,no you can not。我建议编辑该问题以更好地反映您想要做的事情,而不是要求您选择的(有缺陷的)解决方案提供帮助。另外,问题中绝对没有mysql--你如何使用'$ payment_status'与“问题”无关。 – AD7six

回答

4
echo rand('pending','success','failed','refunded'); 

警告:兰特()预计2个参数,4给出

文档:rand()

所以,不,你不能。不是这样的。

这将工作:

$values = array('pending','success','failed','refunded'); 
$payment_status = $values[rand(0, sizeof($values)-1)]; 

或者使用array_rand()(得爱PHP ...适用于所有的功能...):

$values = array('pending','success','failed','refunded'); 
$payment_status = $values[array_rand($values)]; 

为了好玩:你也可以发挥创意并使用shuffle

$values = array('pending','success','failed','refunded'); 
shuffle($values); 
$payment_status = $values[0]; 

虽然这不是任何接近的2运算效率因为它会首先对数组进行混洗,然后返回其中的第一个元素,而不是从列表中选择一个随机元素并将其返回。

4
$rand = $array[array_rand($array = ['pending','success','failed','refunded'])]; 

或者:

$array = ['pending','success','failed','refunded']; 
$rand = $array[rand(0, count($array)-1)]; 

或者......

0

您可以使用以下

$k = array_rand($array); 
$v = $array[$k]; 

看到文档here

享受:)

1

你也可以这样做。

$input = array('pending','success','failed','refunded'); 
echo $input[array_rand($input)]; 

我更喜欢这种方法,因为通过使用这个,你不必指定数组的大小。在某些情况下可能未知。

+0

'我更喜欢这种方法,因为通过使用这个你不必指定数组的大小' - >是不是[sizeof()](http://nl3.php.net/manual/en/ function.sizeof.php)或[count()](http://nl3.php.net/manual/en/function.count.php)是为了? :-) – RobIII

+0

@RobIII我也更喜欢较少的代码行。就像你说过的“PHP ......一切都是......”那么为什么不用一个东西而不是混合多个内置函数呢? –

+0

来自其他平台,只是偶尔使用PHP我倾向于远离'模糊'的功能,如array_rand(和所有其他“有时)有帮助,但无处可找到任何其他语言”功能)。这只是我的习惯... – RobIII