Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:49:18+00:00 2026-06-10T08:49:18+00:00

DB table: Mcourse(Master course )-> contains Course Names Lcourse(Linked Course- courses belongs to a

  • 0

DB table:

  • Mcourse(Master course )-> contains Course Names
  • Lcourse(Linked
    Course- courses belongs to a college) -> contains foreign key
    Mcourse_Id. & college Id.

Nw the problem is

I want to display list of courses available in a college using dropdownlist.

So sql query is:

select Lcourse_Id, Mcourse_Name* from Lcourse inner join Mcourse on Lcourse_Mcourse_Id=Mcourse Id..

*Id & value pair for dropdownlist

I could do this usin createCommand..Its working pretty fine. But i cant do this usin Relations ..Help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:49:19+00:00Added an answer on June 10, 2026 at 8:49 am

    Let’s imagine for a minute that your Mcourse table is called courses and model for that table is called Courses, your Lcourse table is called courses_colleges and your colleges table is colleges and model for that table is Colleges

    Now, You should have Courses model with relations:

    public function relations() {
        return array(
            'colleges' => array(self::MANY_MANY, 'Colleges', 'courses_colleges(course_id, college_id)')
        );
    }
    

    Your Colleges model should have similar relations:

    public function relations() {
        return array(
            'courses' => array(self::MANY_MANY, 'Courses', 'courses_colleges(college_id, course_id)')
        );
    }
    

    Now if you want to print out a dropdown with all courses available for a certain college. In your controller action method get the model of that college including its courses:

    public function actionShow() {
        $id = 1; // We set just some sample id. You could get it from request ofc.
        $college = Colleges::model()->with('courses')->findByPk($id);
        $this->render('show', array('college'=>$college));
    }
    

    Now in your view print out this:

    echo CHtml::dropDownList('courses', '', CHtml::listData($college->courses, 'id', 'name'));
    

    Where 'id' and 'name' are columns of your Courses model.

    Something like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table locations contains locID , lat & long & name values of a certain
I'm retreiving score & course_code from my table, so that all the courses that
table : id (integer primary key) data (blob) I use mysql and sqlalchemy. To
Table users id - Primary Key, AI username - varchar (50) Table logins login_time
Table defintion is create table users ( serial_no integer PRIMARY KEY DEFAULT nextval('serial'), uid
Table: Relatives emp_id dep_id (composite primary key) We have to restrict one employee to
table 'sample' contaning fields [AffiliateId] as a primary key, [AffiliateCode] L, [Name] , [AddressId]
Table kal id integer primary key init char 4 indexed job char4 id init
Table name: Author AuthorID -> primary key FirstName LastName Table name: Titles ISBN ->
Table --------------------------------------------- | id | first_name | middle_name | last_name | --------------------------------------------- | 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.