Reputation: 341
Hi i got this array here and i want to put it into mysql database, here is my array
$v = "Tom: 2000, Bob: 300, Jack: 500"
$x is Array ( [0] => Array ( [0] => Tom [1] => 2000 ) [1] => Array ( [0] => Bob [1] => 300 ) [2] => Array ( [0] => Jack [1] => 500 ) )
and this is my code to put it into database:
$f=explode(",",$v);
for($i=0;$i<sizeof($f);$i++){
$x[$i]=explode(": ",$f[$i]);
$player=$x[$i][0];
$win=$x[$i][1];
$sql = "UPDATE scores SET win=$win WHERE player='$player'";
$result = $conn->query( $sql );
}
but the problem is for loop only puts 'Tom' and '2000' (which are first) into database and nothing happens to other player's row, i think this code should work fine but i cant find what is the problem.
Upvotes: 0
Views: 25
Reputation:
Do the other records exist? I see you're doing an UPDATE and not an INSERT, so maybe the other records mismatch on "player"?
You also might want to use trim() on $player and $win, to remove any whitespace from the explode() output.
Upvotes: 1