pear 里的joinAdd()咋个用?

mrico 2009-12-22 09:20:43
pear 里的joinAdd()咋个用?
怎么返回menu表的 menuText 字段的值?

我要执行这么一条语句:
SELECT *
FROM news
LEFT JOIN menu ON menu.menuID = news.menuID
WHERE menu.menuID =1
ORDER BY newsID DESC
LIMIT 0 , 20



$news = new D_News();
$menu = new D_Menu();
$news->query("set names utf8");
//$news->debugLevel(5);
//$news->joinAdd($news);
$news->whereAdd("menuID=2");
$news->orderBy("newsID desc");
$news->limit("0,7");
$news->find();
$i = 0;
$NewsListArray = array();
while ($news->fetch()) {
$NewsListArray[$i]['newsTitle'] = $news->newsTitle;
$NewsListArray[$i]['menuID'] = $news->menuID;
$NewsListArray[$i]['newsID'] = $news->newsID;
//$NewsListArray[$i]['menuText'] = $menu->menuText;
$i++;
}
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jaxio 2010-01-06
  • 打赏
  • 举报
回复
自己看看吧
jaxio 2010-01-06
  • 打赏
  • 举报
回复
void $DB_DataObject->joinAdd ([object $dataobject [, string $joinType [, string $joinAs [, string $joinCol]]]])
通过添加另一个DataObject实体类的实例创建连接查询。不带参数则清空当前连接查询的相关子句。
第一个参数是要用来进行连接查询的实体。
第二个参数是连接查询的类型,分别有左连接,右连接,内连接。
$joinAs 当你在连接时需要从另一个表中取得多个字段,又觉得写表名太长麻烦的话,可以用这个参数起个别名
$joinCol 当前实体(表)与子实体进行连接匹配的字段。如果当前实体与子实体有多个字段相关联,那么必须要指定这个参数的值。
实例:
$i = new DataObject_Image();
$pi = new DataObjects_Product_image();
$pi->product_id = 24; // set the product id to 24
$i->joinAdd($pi); // add the product_image connectoin
$i->find();
while ($i->fetch()) {
$aR[] = $i -> toArray();
}
相当于下列SQL语句:
SELECT * FROM image,product_image
LEFT JOIN image ON product_image
WHERE product_image.id = 24
AND product_image.pid = product.id

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧