I am trying to add ids like array into mysql in a field called all_ids which has all the ids associated to the user.And when a new id is added it should update the array in mysql fiels and if the id already exists it should not do anything and echo "match found".I am using php GET to supply values of arraylist from android it is decoded to json.But I am unable to add all users in array to mysql.
I really appreciate any help .
Thanks in Advance.
GET code:
www.example.com\example?$id=[123,234,567,8910,11324,1]&sno=12
PHP code:
<?php
$sno=$_GET['sno'];
$id=$_GET['id'];
if (isset($id))
{
$query=mysql_query("SELECT all_ids FROM `user` where sno='$sno';");
$gamerow = mysql_fetch_array($query);
$playerlist = explode(",", $gamerow['all_ids']);
if( empty( $playerlist ) )
{
//empty array
}else{
$obj = json_decode($id);
foreach ($obj as $value) {
if (in_array($value, $playerlist))
{
echo "Match found";
mysql_query("UPDATE user SET all_ids=CONCAT_WS(',',all_ids, '$value') WHERE sno='$sno';");
}
else
{
mysql_query("INSERT INTO user( sno, all_ids ) VALUES ( $sno, $value);");
echo "Match not found";
}
}
}
}
?>