数组值在查询中不起作用

I have some code that worked perfectly a few hours ago, and for some reason it is nbow totally useless.

I have scoured the web for hours trying to work out why I am getting a Notice: array to string conversion error.

On a previous page I post and array of team names to the page where the error message is created.

If I var_dump the array (which is called $teams) all the data is there, every team name in an array.

array(1) { [0]=> array(12) { [0]=> string(6) "Team a" [1]=> string(6) "Team a" [2]=> string(6) "Team a" [3]=> string(6) "Team b" [4]=> string(6) "Team b" [5]=> string(6) "Team b" [6]=> string(6) "Team c" [7]=> string(6) "Team c" [8]=> string(6) "Team c" [9]=> string(6) "Team d" [10]=> string(6) "Team d" [11]=> string(6) "Team d" } }

Note, the team names are repeated as this is a fixture list, so each team plays each team.

However, the array to string conversion error is occuring in my query.

So, at the top of the page I create an array from the data posted like this...

$team[]=$_POST['team'];

then in my query I run a for loop and run the query, summarised as follows;

$count=count($team);
for($i=0;$i<$count;$i++ {
$query=$database->query("UPDATE pool_a SET ......where team_name='$team[$i]')"

I am so confused, I did a bit of editing earlier to try to add further queries to produce tables for pool_b, pool_c etc but I scrapped them and I am sure the code is as it was this morning.

Any help would be much appreciated.

Thanks

Based on the var_dump() you posted, it looks like you array is actually located at $team[0].

It looks like you need to change this:

$team[] = $_POST['team'];

to this:

$team = $_POST['team'];

Assigning to $team[] in essence gave you an extra array wrapper around your data.

Since you also have duplicate values in the array, before querying the database you should reduce array only to unique values.

$team = array_unique($team);

You would be best served using a single query with all your items in it:

$query = "UPDATE pool_a SET ... WHERE team_name IN('" . implode("','", $team) . "')";
$database->query($query);