2015-02-07 85 views
-1

得到以下错误:警告:兰特()预计参数长

Warning: rand() expects parameter 2 to be long, array given in C:\wamp\www\honeydev\python.php on line 61

以下是代码:

58 $max_passno=$dbo->prepare("select count(*) from user_password"); //find the max. no of entries in user_password table 
59 $max_passno->execute(); 
60 $row = $max_passno->fetch(); 
61 $no2 = rand(1, $row); //select a random number 

有人建议,需要什么样的变化来解决这个好吗?

+0

'$ row'是一个数组,不是数字。数组中的元素,而不是数组本身。 – deceze 2015-02-07 07:08:41

+0

'$ count = $ max_passno-> fetchColumn(); $ no2 = rand(1,$ count);' – 2015-02-07 07:13:00

+0

谢谢@Jack !!!你应该已经发布了这个答案! – Technolust 2015-02-07 07:50:09

回答

2

再次阅读错误消息。它很清楚地说明了问题的症结所在。

rand(1, 999);

参数2需要是数字。出于某种可怕的原因,你在那里扔了一个数组。很有趣,但它不会那样工作。

$max_passno=$dbo->prepare("select count(*) as count from user_password"); //find the max. no of entries in user_password table 
$max_passno->execute(); 
$row = $max_passno->fetch(); 
$no2 = rand(1, $row['count']); //select a random number 

为了将来的参考,它可能有助于检查有问题的变量。

var_dump($row);

相关问题