You can fix this problem by storing the data in a manner appropriate for a relational database and then extracting the data in a format appropriate for presentation.
You seem to have a need for a "UserFav" table, with one row per use and one per "fav". If you had such a structure, your query would be:
select id, name, group_concat(distinct uf.favid order by uf.id) as favs
from table t join
UserFav uf
on t.id = uf.userid
group by t.id;
Attempting to do such string operations in the database is, shall I say, silly. Databases are designed to do some very sophisticated data manipulations. Use them. Don't try to fit a round peg into a square hole.