I'm using this function;
function add_profile_visitor($add_uid,$to_uid,$visitors_list)
{
global $db;
$list = trim($visitors_list);
$list_users = explode(",",$list);
if (in_array($add_uid,$list_users))
{
return;
}
else
{
if (strpos($list_users,",") || strlen($list_users) > 0)
{
$newlist = $list_users.",".intval($add_uid);
}
else
{
$newlist = intval($add_uid);
}
$db->query("UPDATE users SET profile_visitor='".$db->escape_string($newlist)."' WHERE uid=".$to_uid);
}
}
I want to add a User ID if its not present already in the field profile_visitor
. For your notice, the profile_visitor
list is comma separated list. Here are the variable's legend:
$add_uid
= The user id that is going to be inserted in profile_visitor
if its not present in already. $to_uid
= The User ID where profile_visitor
column is present and the $add_uid add in if its not present. $visitors_list
= The comma separated list of profile visitors. Before adding any User ID that list will be empty (obviously)
The issue is: Each time the page loads (where that function is running) the list profile_visitor
has the new User ID instead of adding the new User ID to the list.
Please help
Change your function to this:
function add_profile_visitor($add_uid,$to_uid,$visitors_list)
{
global $db;
$list = trim($visitors_list);
$list_users = explode(",",$list);
if (in_array($add_uid,$list_users))
{
return;
}
else
{
if (strpos($list,",") || strlen($list) > 0)
{
$newlist = $list.",".intval($add_uid);
}
else
{
$newlist = intval($add_uid);
}
$db->query("UPDATE users SET profile_visitor='".$db->escape_string($newlist)."' WHERE uid=".$to_uid);
}
}