我想从2db中选择值。
image_db => id, image_adress, category, product_id;
product_db => id, name, price;我想从特定类别中选择图像,并为每个图像选择产品的数据
我该怎么办?
这是正确的吗?
$select = $image_model->select()
->where('category = ?',$category)->from(array('i'=>'image_db'),
array('adress','product_id'))->join(array('p'=>'product_db'), 'i.product_id'='p.id');发布于 2013-12-11 17:06:45
假设它们都在同一个数据库中,这似乎是正确的,但我认为您是在控制器中使用它。
但是你可以在模型中使用它,因为zend是一个MVC,
public function getProducts($category)
{
$sql=$this->select()
->setIntegrityCheck(false)
->from(array('i'=>'imagemaster'),array())
->join(array('p'=>'projectmaster'),'i.project_id=p.id',array())
->where('category = ?',$category)
->group('p.id');
$resultSet = $this->fetchAll($sql);
return $resultSet;
}还没有测试过,但是应该可以工作了..希望能有所帮助..。
https://stackoverflow.com/questions/20513651
复制相似问题