0

I hope I'm asking this question in an understandable way. I've been working on an app that has been dealing with 1 table ( jobschedule ). So, I have models/Jobschedule.php, models/JobscheduleMapper.php, controllers/JobscheduleController.php, view/scripts/jobschedule/*.phtml files

So in my controller I'll do something like this:

    $jobnumber = $jobschedule->getJobnum();
    $jobtype = $jobschedule->getJobtype();

    $table = $this->getDbTable();

public function listAction()
{
    $this->_helper->layout->disableLayout();
    $this->view->jobnum = $this->getRequest()->getParam( 'jobnum', false );
    $this->view->items = array();       

    $jobschedule = new Application_Model_Jobschedule();
    $jobschedule->setJobnum( $this->view->jobnum );

    $mapper = new Application_Model_JobscheduleMapper();
    $this->view->entries = $mapper->fetchAll ( $jobschedule );
}

and then in my mapper I I do something like:

        $resultSet = $table->fetchAll($table->select()->where('jobnum = ?', $jobnumber)->where('jobtype = ?', $jobtype) );
        $entries   = array();
        foreach ($resultSet as $row) {
            $entry = new Application_Model_Jobschedule();
            $entry->setJobnum($row->jobnum)
                  ->setJobtype($row->jobtype)
                  ->setJobdesc($row->jobdesc)
                  ->setJobstart($row->jobstart)
                  ->setJobend($row->jobend)
                  ->setJobfinished($row->jobfinished)
                  ->setJobnotes($row->jobnotes)
                  ->setJobid($row->jobid);
            $entries[] = $entry;
        }
        return $entries;
    }

Then in my view I can manipulate $entries. Well, the problem I'm coming across now is that there is also another table called 'jobindex' that has a column in it called 'jobno'. That 'jobno' column holds the same record as the 'jobnum' column in the 'jobschedule' table. I need to find the value of the 'store_type' column in the 'jobindex' table where jobindex.jobno = joschedule.jobnum ( where 1234 is the jobno/jobnum for example ). Can someone please help me here? Do I need to create a jobindex mapper and controller? If so, that's done ... I just don't know how to manipulate both tables at once and get the record I need. And where to put that code...in my controller?

4

2 回答 2

0

如果我对您的理解正确,您需要将“jobindex”表加入“jobschedule”表。

...
$resultSet = $table->fetchAll(
    $table->select()->setIntegrityCheck(false)
        ->from($table, array('*'))
        ->joinLeft(
            'jobindex',
            'jobindex.jobno = jobschedule.jobnumber',
            array('store_type'))
        ->where('jobnum = ?', $jobnumber)
        ->where('jobtype = ?', $jobtype)
        ->where('jobindex.store_type = ?', $_POST['store_num'])
);
....

根据 'jobschedule' 与 'jobindex' 的关系,您可能需要一个内部连接 ​​( joinInner()) 来代替。

禁用表之间的setIntegrityCheck(false)引用完整性,这仅在您向它们写入时才重要。对于像这样的查询,您可以禁用它并继续(否则它将引发异常)。

于 2012-04-11T01:41:11.747 回答
0

如果我理解正确,这是从数据库中提取数据所需的 SQL 查询:

SELECT `jobschedule`.* FROM `jobschedule` INNER JOIN `jobindex` ON jobindex.jobno = jobschedule.jobnum WHERE (jobindex.jobtype = 'WM')

在 Zend 中组装这个 SQL 查询看起来像这样:

    $select->from('jobschedule', array('*'))
    ->joinInner(
        'jobindex',
        'jobindex.jobno = jobschedule.jobnum',
        array())
    ->where('jobindex.jobtype = ?', $jobtype);

让我们知道这是否是您正在寻找的。

于 2012-04-11T08:06:49.167 回答