Thanks for your quick replay. Here is what I did so far:

I created method listing() inside voters_controller:

function export_xls()
                {
                        $this->layout = 'export_xls';
                        $locations = $this->Location->find('list');
                       $report = array();
                        foreach ($locations as $locationId => $locationName)
                        {
                                foreach ($statuses as $status)
                                {
                                $report[$locationId][$status] = 
$this->Voter->find('count',
array(
                                'conditions' => array('Voter.location_id' =>
$locationId,'Voter.status' => $status)));
                                }

                        }

                $this->set('locations','report');

                }

Also I created layout named expost_xls iside layout directory and
inside view/voters folder I created file export_xls.ctp:

<?php foreach($rows as $row):

                        echo '<tr>';
                        echo '<td 
class="tableTdContent">'.$location['Location']['name'].'</
td>';






                        /*echo '<td 
class="tableTdContent">'.$report['LocationName'][1].'</
td>';*/

                        echo '</tr>';

                        endforeach; ?>

Here I have I problem, because  I got error when I try to display
data. I apologize if this is blunder question but I'm new in Cake and
struggling to cope with this.
What argument I have to supply to view to correctly display data.

On Jun 14, 4:49 pm, calvin <[email protected]> wrote:
> $locations = $this->Location->find('list');
> $report = array();
> foreach ($locations as $locationId => $locationName) {
>   foreach ($statuses as $status) {
>     $report[$locationId][$status] = $this->Voter->find('count', array(
>       'conditions' => array(
>         'Voter.location_id' => $locationId,
>         'Voter.status' => $status
>       )
>     ));
>   }}
>
> $this->set(compact('locations', 'report'));
>
> I'd recommend reading the Cookbook and doing the blog example if
> you're still unsure as to how to send data from a controller to the
> view.
>
> On Jun 14, 5:04 am, Kiza <[email protected]> wrote:
>
> > Hello,
>
> > I'm currently working on app for Voters registering and it's pretty
> > much completed.
>
> > I have 5 tables in database: voters, locations, categories, users,
> > statuses.
>
> > Table voter is in "belongs to" relationship with other tables and
> > tables have following structure:
>
> > voters
>
> > id int(11) NOT NULL auto_increment,
>
> > firstName varchar(50) NOT NULL,
>
> > lastName varchar(50) NOT NULL,
>
> > phone varchar(50) NOT NULL,
>
> > status_id int(11) NOT NULL,
>
> > user_id int(11) NOT NULL,
>
> > location_id int(11) NOT NULL,
>
> > category_id int(11) NOT NULL,
>
> > locations
>
> > id int(11) NOT NULL auto_increment,
>
> > name varchar(50) NOT NULL,
>
> > statuses
>
> > firstName0 int(11) NOT NULL auto_increment,
>
> > firstName1 varchar(50) NOT NULL,
>
> > categories
>
> > firstName2 int(11) NOT NULL auto_increment,
>
> > firstName3 varchar(50) NOT NULL,
>
> > What I would like to do is display all locations names, each followed
> > with a count of the number of voters from that locations for status 1,
> > status 2 and so on
>
> > .
>
> > Basically I must generate report witch has following structure:
>
> > Location name| Number of voter in status 1 | Number of voters in
> > status 2 | etc.
>
> > Location 1
>
> > Location 2
>
> > Location 3
>
> > etc
>
> > I guessing that I should use find('count') or counterCache but I just
> > don't know how to write that query or how to send result to view. This
> > is really major problem for me so if anyone have some suggestion it
> > will be appreciated.
>
> > If you need some additional information I will be happy to provide it
> > in order to solve this problem.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to