views:

2

answers:

0

Can anyone help me work out why I'm not able to extract the classes.id data in the following Zend_Db_Select join query.

I need the class id to allow me to include an 'edit class' link. Problem is the query is outputting an id for each class which is different to classes.id in the database table.

What am I doing wrong?

I have three tables: classes, teacher and day whose structure is as follows:

classes id [primary key a/i] classname [varchar] duration [int] time [time] teacher_id [int] day_id [int]

teacher id [primary key a/i] firstname [varchar] lastname [varchar]

day id [primary key a/i] dayname [varchar]

I have written the following Zend_Db_Select query to join the tables:

public function listteacherClass()
    {
        $db = Zend_Registry::get('db');
        $select = new Zend_Db_Select($db);
        $statement = $select->from(array('t' => 'teacher'),
                                array('c.classname', 'c.duration', 'c.time', 'c.id', 't.firstname', 't.lastname', 'd.dayname'))
                            ->join(array('c' => 'classes'), 'c.teacher_id = t.id')
                            ->join(array('d' => 'day'), 'c.day_id = d.id')
                            ->order(array('d.id ASC', 'c.time ASC'));
        $results = $db->query($statement);
        $rows = $results->fetchAll();
        return $rows;
    }

This query lists the teacher, days and classes data from the three database tables correctly in an array, but ...

It doesn't pull the classes.id data from the classes table. The classes.id it outputs is the same as the day.id data.

If I restrict the above to one join on the teacher and classes tables, then the correct classes.id appears in the array.

Is there something wrong with the syntax of my query that is creating this problem?

Many thanks for any help. This one's tearing my hair out!