first, i've done homework (researched), more bug inside code drives me crazy , need more eyes solve it. please if have idea why happening?
the problem:
in mysql table keeping project id's "1,2,3,4,"
then via ajax i'm checking if project_id part string or not, if not part try add (example, if 13 part above) , after update should "1,2,3,4,13," somehow i'm ending "13,".
here's relevant part of code im trying fix:
$result = mysql_query("select `assigned_projects` `users` `user_id`=`$user_id`"); $user_proekti = mysql_fetch_row($result); $str_proekti = $user_proekti[0]; if (!(strpos($str_proekti, $proekt))) { //means project not in list , should added $new_proekti = $str_proekti.$proekt.","; //$str_proekti empty string?????? $assign_new_project = mysql_query("update `users` set `assigned_projects` = `$new_proekti` `user_name` = `$dodeleno` "); $update_track_changes = mysql_query("update `track_changes` set `proekts_order` = `1`"); }
try as
$str = "1,2,3,4,"; $input = "13"; $arr = array_filter(explode(',', $str)); if (!in_array($input, $arr)) { array_push($arr, $input); } echo implode(',', $arr);
Comments
Post a Comment