How to show one to many relation

I have one course table which has field subjec_id with comma separate value ex(1,2) the subject id and subject name are stored in another table called subject

1 —>c

2 —>c++

3 —>PHP

now my case is, i want to show c,c++ instead of showing 1,2 please help me , thanks in advance

That is not the standard way for do this job.

Usually for this many-many relations is better to create a third table in wich you save the relations, like:


1 --->c

2 --->c++

3 --->PHP


1 => system programming

2 => web designer


1 1

1 2

If you follow this standard schema, Gii will authomathically generate the many_many relation for get.

Otherway if you want to proceed on your approach, you can use a condition:

Subject::model()->findAll("id IN ($model->subjec_id)");

But this is a deprecated approach.

Thank you i will try

could u tell me where should i use this code because im new to yii

Subject::model()->findAll("id IN ($model->subjec_id)");

You should have a model Subject.

When you have the need to find all subject wich are in a comma separated list, you can write:

$subjects=Subject::model()->findAll("id IN ($commaSeparatedList)");

Where in $commaSeparatedList you have something like 1,2.

Anyway I recomand you, if you are new to Yii, to follow the standard path at the beginning, this will result in a better comprehension.

Create a db structure with 3 tables, and you will have the possibility to use all powers of AR