I have a script, which updates my table's column and writes an id to it.
I need to check whether the column is empty or not. If it is not, I add a ,
.
$subs = mysql_fetch_array(mysql_query("SELECT subscribed_user_id FROM users WHERE user_id=".(int)$_GET['user']));
$subs_array = array();
$subs_array=explode(',', $subs['subscribed_user_id']);
if(!in_array($_COOKIE['user_id'], $subs_array))
{
if($subs['subscribed_user_id']=='')
{
$add='';
} else {
$add = $subs['subscribed_user_id'].',';
}
mysql_query("UPDATE users SET subers=subers+1, subscribed_user_id='".$add.$_COOKIE['user_id']."' WHERE user_id=".(int)$_GET['user']);
}
I have an idea: always add ,
. But when I select it, I don't use the full length of the array. But, for example array.length-2
, I think that it is not OK and I need to know how I can improve this script.