count total matching id if a single column contain multiple value separated by comma I have problem in my school management software. 

I have to count how many classes a teacher has in all week, for this the admin may assign more than one teacher to a class and that selected teacher is inserted in database by their ids. If there are multiple teachers they will be inserted in single column separated by commas. 

I have to count the total number of classes for a teacher.

How could I create such a query

mysql_num_rows(mysql_query("select * from table_teacher where employee_id in (1))
The root cause of your problem is that database is not normalized. Assuming your table looks like:

CREATE TABLE COURSES
( APPLICATION_CODE ... NOT NULL PRIMARY KEY
, ...
, TEACHERS VARCHAR(100) NOT NULL );

INSERT INTO COURSES (APPLICATION_CODE, TEACHERS)
VALUES ('MA101', '1,2,5');


The correct thing to do is to normalize this into two tables:

CREATE TABLE COURSES
( APPLICATION_CODE ... NOT NULL PRIMARY KEY
, ... );

CREATE TABLE COURSE_TEACHERS
( APPLICATION_CODE ... NOT NULL 
, TEACHER_ID INT NOT NULL 
,     PRIMARY KEY (APPLICATION_CODE, TEACHER_ID) );

INSERT INTO COURSES (APPLICATION_CODE)
VALUES ('MA101');

INSERT INTO COURSE_TEACHERS (APPLICATION_CODE, TEACHER_ID)
VALUES ('MA101', 1), ('MA101', 2), ('MA101', 5);


In this case, it is sufficient to count the rows where TEACHER_ID = 1

SELECT COUNT(1) 
FROM COURSE_TEACHERS
WHERE TEACHER_ID = 1;


Not only will it be easier to ask questions like this, the queries will be much more efficient since they can utilize indexes in a way that is not possible in your current model.

That said, if you know that the teacher string always looks like for example:

' 1, 2, 5,'

You can use LIKE to count the rows:

SELECT COUNT(1) 
FROM COURSES WHERE TEACHERS LIKE '% 2,%';


Pitfalls, if the last item is not terminated with the separator token (in this case ",") you need to handle that in a special predicate. The same goes for the start item, it needs to start the same way as the remaining ones.

If you can not trust the string to be in this simple form, you may be able to come up with a regular expression that describes a teacher item in the list of teachers.