使用 Zend Framework PHP 连接表 [英] Joining Tables With Zend Framework PHP
问题描述
我对 Zend 框架比较陌生.
I am relatively new to the Zend Framework.
我了解 Zend_Table 的用法,并且可以使用 Zend 函数从与该类关联的表中获取数据.
I understand the usage of Zend_Table and can obtain data using the Zend functions from the table associated with that class.
例如,我有一个视频表,在另一个表中,我有视频与其所属类别之间的关联.
For example I have a video table and in another table I have the association between the video and what category it is in.
我有点困惑如何在框架内激活如下所示的选择:
Im a little stumped how to active a select like the following within the framework:
SELECT * FROM video
,category
WHERE category
.category_id
= 3 AND video
.id
= category
.video_id
SELECT * FROM video
,category
WHERE category
.category_id
= 3 AND video
.id
= category
.video_id
任何建议都会很棒.
谢谢.
推荐答案
$db->select()->from('video')->joinInner('category','video.id = category.video_id')->where('category.category_id = ?',3)
顺便说一句:看起来你的数据库设计有误.您的视频表中应该有 category_id(如果 1 个视频 -> 1 个类别)或有一个连接表 (M:N),但将视频 ID 存储在类别中似乎是错误的.
BTW: It looks like you have wrong db design. You should have category_id in your video table (if 1 video -> 1 category) or have a connection table (M:N), but it seems wrong to have video id stored in category.
这篇关于使用 Zend Framework PHP 连接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!