2015-02-07 4 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

+0

'$ count = $ max_passno-> fetchColumn(); $ no2 = rand (1, $ count); ' –

+0

감사합니다. @ 잭! 답변을 게시 했어야합니다! – Technolust

답변

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

관련 문제