-3

Below is the code:

$result=mysql_query("select * from choices where a_id='$taskid'")or die(mysql_error());
while($row=mysql_fetch_assoc($result))
{ print_r($row); }

Why did I only got []? What's wrong?

More: It can not be empty. The more complete code is as follows:

$result=mysql_query("select * from choices where a_id='$taskid'")or die(mysql_error());
   $resultset=array();
 while($row=mysql_fetch_assoc($result))
{  
    $temp=shuffle(array_slice($row,3));

    $row1=array_splice($row,3,7,$temp);
    $resultset[]=$row1;

}

echo json_encode($resultset);

I want to shuffle the mysql query results from index 3 to index 7, only to find that the values from index 3 to index 7 are returned without being shuffled. Other values are undefined in Javascript.

What's wrong?

Charles
  • 50,943
  • 13
  • 104
  • 142
Steven
  • 24,410
  • 42
  • 108
  • 130
  • 1
    This is a duplicate from your own question asked 30min. ago: http://stackoverflow.com/questions/1777801/why-do-i-get-resource-id-4-when-i-apply-printr-to-an-array-in-php . – GmonC Nov 22 '09 at 04:53
  • I think you should post what is inside the database and what the value of $taskid at the time of execution. – Natalie Adams Nov 22 '09 at 04:57

1 Answers1

1

$row is empty. Meaning nothing was returned from your SQL query. Try the following to make sure the query is executing exactly what you expect:

echo "select * from choices where a_id='$taskid'";
mauris
  • 42,982
  • 15
  • 99
  • 131
Darrell Brogdon
  • 6,843
  • 9
  • 47
  • 62
  • Are you sure? It seems like if that were the case the code should never go into the while loop in the first place. – Jonathan Nov 22 '09 at 04:55