LOSTBOY Posted November 23, 2007 Share Posted November 23, 2007 hi am an PHP Beginner when i try this code it throws if (!in_array($qno,$tempArray)) Warning: in_array() [function.in-array]: Wrong datatype for second argument what can i do to overcome this warning! Thanks in Advance Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 23, 2007 Share Posted November 23, 2007 well it just states that the second argument is not an array Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 23, 2007 Share Posted November 23, 2007 as for overcoming it this code should work, you just stop the error not the functionality if (!@in_array($qno,$tempArray)) Quote Link to comment Share on other sites More sharing options...
LOSTBOY Posted November 23, 2007 Author Share Posted November 23, 2007 thanks for ur valuable reply ............ Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 23, 2007 Share Posted November 23, 2007 No problem at all, but I would suggest to you never use the @ operator to overide an error it becomes very hard to debug, find out why $tempArray is not an array and try to overcome it before the if statement (something like if its not an array, initialize it to an array), it would be a good programming practice Quote Link to comment Share on other sites More sharing options...
LOSTBOY Posted November 23, 2007 Author Share Posted November 23, 2007 here is my code.....actually i want to generate Randam Quiz's .....as single quiz per page here $_session['$max'] is the maximum questions that user select from our db if (!isset ($_SESSION['$max'])){ $_SESSION['$max']=$_POST['sel_ques']; $tempArray= array(); } do { $qno=rand(1, $_SESSION['max']); if (!@in_array($qno,$tempArray)) { $tempArray[$r] = $qno; $query="SELECT * FROM question WHERE qid=$qno" ; $result=mysql_query($query); $id=mysql_result($result,$i,"qid"); $question=mysql_result($result,$i,"question"); mysql_result($result,$i,"question"); $query1="SELECT * from answer where qid=$id"; $result1=mysql_query($query1); $r++; } But it not working properly .......plz give ur suggestions Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 23, 2007 Share Posted November 23, 2007 try this code if (!isset ($_SESSION['$max'])){ $_SESSION['$max']=$_POST['sel_ques']; } if (!isset($_SESSION['tempArray'])) { $_SESSION['tempArray'] = array(); } $query = "SELECT * FROM question limit 1"; if (!empty($_SESSION['tempArray'])) { $query="SELECT * FROM question WHERE qid not in (".implode(",",$_SESSION['tempArray']).") limit 1" ; } $result=mysql_query($query); $id=mysql_result($result,1,"qid"); $_SESSION['tempArray'][] = $id; $question=mysql_result($result,1,"question"); mysql_result($result,$i,"question"); $query1="SELECT * from answer where qid=$id"; $result1=mysql_query($query1); and please backup your old code incase I am wrong Quote Link to comment Share on other sites More sharing options...
LOSTBOY Posted November 23, 2007 Author Share Posted November 23, 2007 ur code is not wrong ...but doesnt bring any data from data base.................................................... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.