Hey guys,
 I need help with a problem i ran into...

I have three tables -

Table1:districts
collumns: id,district

Table2:madnals
collumns: id,district_id,mandal

Table3:invoices
collumns: id,mandal_id,invno

with grigri's help from a previous post of mine i was able to populate
a dropdown list with the districts names while accessing the Mandals
model.

What I'am trying to do now is create a view.ctp that will display
following data in a tabular format-

mandal | district | invno

I wish to do this accessing my Invoice model.
The code in my Invoice model is so:

class Invoice extends AppModel
{
   var $belongsTo = array(

                                                 'Mandal' =>
                             array('className'  => 'Mandal',
                                   'conditions' => '',
                                   'order'      => '',
                                   'foreignKey' => 'mandal_id'));
}

The invoices_controller code is so:

class InvoicesController extends AppController
 {

var $uses = array('District','Mandal');

        function view()
        {
          $this->set('invoices', $this->Invoice->find('all'),$this->paginate
());
        }
 }

I print the data into the view.ctp using a loop and following
variables:

<table>
        <tr>
                <th>Invoice</th>
                <th>District</th>
                <th>Mandal</th>
        </tr>

        <!-- Here is where we loop through our $invoices array, printing out
invoice info -->
       <?php foreach ($invoices as $invoice): ?>
        <tr>
         <td><?php echo $invoice['Invoice']['invno']; ?></td>
        <td><?php echo $invoice['Mandal']['district_id']; ?></td>
         <td><?php echo $invoice['Mandal']['mandal']; ?></td>
        </tr>
        <?php endforeach; ?>
</table>

the Mandal name appears as expected, but i cant get the district name
to appear, instead the district_id itself appears as a number.

Invoice     |   District      |     Mandal
    1                12               Bhongir
(correct)  (id appears        (correct)
                  not name)

Can someone please help me with a solution to this problem? I used
roundabout methods for now, but my code is getting way to complex. I
know the solution has to do something with the model.....can someone
please help? I would greatly appreciate it. :)

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

Reply via email to