Passing a variable through raw sql - Yii
<p>I am currently trying to pass through a variable to act like a where clause so I can pass it to the URL and display content for each event on a page.</p>

<p>To do this, I'd need to pass the event_id.</p>

<pre><code>public function exportSearch($event_id){

        $query = "SELECT
                    u.prefix AS  'Title', 
                    u.forename AS  'Forename', 
                    u.surname AS  'Surname', 
                    u.telephone AS 'Mobile Number',
                    u.email AS  'Email Address', 
                    ea.checkin_status_id AS 'checked in',
                    u.update_time AS  'Register Date', 
                    eg.name AS 'Event Group Registered', 
                    e.name AS  'Session Registered', 
                    u.bio AS 'User Information',
                    u.dob AS 'Date of Birth',
                    u.company AS 'Company',
                    u.company_role AS 'Company Role',
                    CONCAT(u2.forename, ' ', u2.surname) AS 'Guest of',
                    MAX(CASE WHEN uv.user_type_variables_id = 1 THEN uv.value ELSE NULL END) AS Question1,
                    MAX(CASE WHEN uv.user_type_variables_id = 2 THEN uv.value ELSE NULL END) AS Question2,
                    MAX(CASE WHEN uv.user_type_variables_id = 3 THEN uv.value ELSE NULL END) AS Question3,
                    MAX(CASE WHEN uv.user_type_variables_id = 4 THEN uv.value ELSE NULL END) AS Question4,
                    MAX(CASE WHEN uv.user_type_variables_id = 5 THEN uv.value ELSE NULL END) AS Question5,
                    MAX(CASE WHEN uv.user_type_variables_id = 6 THEN uv.value ELSE NULL END) AS Question6

                    FROM tbl_event_attendees AS ea

                    LEFT JOIN tbl_user AS u ON ea.user_id = u.id
                    LEFT JOIN tbl_event AS e ON ea.event_id = e.id
                    LEFT JOIN tbl_event_groups AS eg on e.group_id = eg.id
                    LEFT JOIN tbl_user AS u2 ON ea.guest_of_user_id = u2.id
                    LEFT JOIN tbl_user_variables AS uv on u.id = uv.user_id


                    GROUP BY ea.id";

           // $query-&gt;params([':event_id' =&gt; $event_id]);

        $count=Yii::app()-&gt;db-&gt;createCommand($query)-&gt;queryScalar();
        return $sqlDataprovider = new CSqlDataProvider($query, array(
                'totalItemCount'=&gt;$count,
                'sort'=&gt;array(
                    'attributes'=&gt;array(
                       // 'event_name'=&gt;Event::model()-&gt;getAttributeLabel('name'), // csv of sortable column names
                        //'Question1' =&gt; EventAttendees::model()-&gt;getAttributeLabel('Question1'),
                        // 'Forename',

                    )
                ),
                 'pagination'=&gt;array(
                 'pageSize'=&gt;$count, //Show all records
        ),
            ));
     }
</code></pre>

<p>My idea was to use $query->params to do this and then throw it over to the view but had no luck.</p>

<p>It needs to display something like WHERE ea.event_id = $event_id but I can't seem to pass it through via the raw sql.  </p>