Your database table with the list of values stored in one column is not 'normalize'. You can do a web search on database normalization to find what the means.
You would never store a list of values in one column. You would store a separate row for each of those values instead. Once you make this change to your database table design, you can write one JOIN'ed query that gets all the data you want, then simply loop over that data.
Next, the php mysql statements are obsolete and have been removed from php. If you are taking a programming course or learning on your own, you are learning out of date information. You should instead be using the php PDO statements and you should be using a prepared query to supply data to the sql query statement. You can research the php.net documentation to find out what PDO and prepared queries are.
Lastly, your database tables, columns, and php variables should have meaningful names so that anyone looking at the code and queries can deduce what they are doing. This is especially important if you are asking someone else to look at your code, such as when you post it in a programming help forum.