I have a list of contact for friends in a database, what I am trying to do is retrieve a users contacts, see if the other user id is in there, if it is not then add it then put it back in the database.
however I seem to keep adding the same contact into the array even when it is already thereand the output is stored in my db like this
a:2:{i:0;a:1:{i:0;i:1070;}i:1;i:1070;}
This is the product of the in_array not evaluating as true on the first check. Every time time the function is run more and more "layers" are added.
Thanks in advance
here is my code
function addfarmertohunter($hunterid,$farmerid){
$select="SELECT contacts from users where id=$hunterid";
$result=mysql_query($select)or die(' add farmer error'. mysql_error());
if (mysql_num_rows($result)==1){
$row=mysql_fetch_array($result);
$contacts=$row[0];
if($contacts==null||$contacts=="N;"||$contacts==""){
$temp=array();
array_push($temp, $farmerid);
}else{
$temp=array(unserialize($contacts));
if(in_array((int)$farmerid, $temp)==FALSE){array_push($temp, $farmerid);}
}
$strcontacts=serialize($temp);
$ins="UPDATE users set contacts='$strcontacts' where id=$hunterid";
mysql_query($ins) or die('add farmer e'.mysql_error());
}
}