tags:

views:

103

answers:

1

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?

+1  A: 

$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'";
Darrell Brogdon
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