Jump to content

"Wrong datatype for second argument" while using in_array()


LOSTBOY

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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  :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.