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 6650963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:57:15+00:00 2026-05-26T00:57:15+00:00

There’s two tables, attendee , and group . both have a gender field. Each

  • 0

There’s two tables, attendee, and group. both have a gender field. Each attendee is assigned to 1 group. I’ve got my CGridView successfully showing the number of attendees, but when I added code to filter on gender, I get the following error. To calculate the number of attendees in a group, I’m manually performing a join; but the join makes the field ‘gender’ ambiguous. Is there any way to specify in the filter that it should use the ‘t’ or base table?

When I load the view it operates correctly; when I click to sort on gender, it gives me this message:

Error Message

>     Error 500: <h1>CDbException</h1>
>     <p>CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'gender'
> in where clause is ambiguous. The SQL statement executed was: SELECT
> COUNT(*) FROM (SELECT t.*, IFNULL( count(tbl_attendee.id), 0) as
> attendeeCount FROM `tbl_group` `t` LEFT JOIN tbl_attendee ON
> tbl_attendee.group_id = t.id WHERE gender LIKE :ycp0 GROUP BY t.id) sq
> (/Applications/MAMP/htdocs/yiiroot/framework/db/CDbCommand.php:516)</p><pre>#0
> /Applications/MAMP/htdocs/yiiroot/framework/db/CDbCommand.php(411):
> CDbCommand->queryInternal('fetchColumn', 0, Array)

Model Code

$criteria=new CDbCriteria;
$criteria->compare('name',$this->name,true);
$criteria->compare('gender',$this->gender,true);                
$criteria->compare('agegroup',$this->agegroup,true);
$criteria->select = 't.*, IFNULL( count(tbl_attendee.id), 0) as attendeeCount';
$criteria->join = 'LEFT JOIN tbl_attendee ON tbl_attendee.group_id = t.id';
$criteria->group = 't.id';

$sort = new CSort();
$sort->attributes = array(
    'attendeeCount'=>array(
    'asc'=>'attendeeCount ASC',
    'desc'=>'attendeeCount DESC',
    ),
    '*', // add all of the other columns as sortable
);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>$sort,
));

View Code

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'group-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
       'name',
       array(
        'name'=>'gender',
        'value'=>'Group::$genderLabels[$data->gender]',
        'filter'=>Group::$genderLabels, // <-- This is the filter that breaks.
                                        // $genderLabels = array('Female','Male);
    ),
  • 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-05-26T00:57:16+00:00Added an answer on May 26, 2026 at 12:57 am

    Ah! I got it.

    Changed this line in the model code:

    $criteria->compare('gender',$this->gender,true);

    to

    $criteria->compare('t.gender',$this->gender,true);

    Found the answer here.

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

Sidebar

Related Questions

There are two tables: aspnet_users and aspnet_membership. Can anyone elaborate on the reasons why
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There are numerous Agile software development methods. Which ones have you used in practice
There are several types of objects in a system, and each has it's own
There is a field in my company's Contacts table. In that table, there is
There is this strange situation I'm fighting on. I have 3 pages, les call
There are two major fix engines: opensource QuickFix http://www.quickfixengine.org/ commercial Fix Antenna http://www.b2bits.com/trading_solutions/fix_engines/fix_engine_cpp.html What
There have been several questions on SO regarding getting Contacts numbers using the Contacts
There are two common ways to run mobile version of a website: Detecting the

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.