本帖最后由 lidq.jingwu 于 2009-11-11 10:27 编辑
资讯
查资讯自定义字段- SELECT i.*,n.*,c.type as c_type,c.name as c_name,c.displayorder as c_displayorder,c.customfieldtext as c_customfieldtext,c.isdefault as c_isdefault,c.isshare as c_isshare FROM supe_spaceitems i, supe_spacenews n, supe_customfields c WHERE i.itemid = n.itemid AND n.customfieldid = c.customfieldid AND n.customfieldid !=0
复制代码 通过supe_spaceitems,supe_spacenews,supe_customfields三表联查来取得数据。
查资讯列表,同时查对应的图片附件- SELECT * FROM supe_spaceitems i, supe_attachments a WHERE i.picid = a.aid
复制代码 查资讯列表和内容,同时查对应的图片附件- SELECT i.*, n.message, a.* FROM supe_spaceitems i, supe_spacenews n, supe_attachments a WHERE i.picid = a.aid AND i.itemid=n.itemid
复制代码 调用模型中图片,标题,内容数据- SELECT * FROM supe_[模型英文ID]message m,supe_[模型英文ID]items i WHERE m.itemid=i.itemid
复制代码 supe_[模型英文ID]message 与 supe_[模型英文ID]items 是存储模型信息的主表,添加的字段也会添加在 supe_[模型英文ID]message 里面,将这两个表联起来就可以查询出想要的大部分数据。
论坛
查询论坛中今天发帖总数与论坛总帖数- select sum(posts) as posts , sum(todayposts) as todayposts from cdb_forums
复制代码 查询论坛主题,在设置主题分类时,显示出主题分类名称- SELECT * FROM 数据库名.cdb_threads t, 数据库名.cdb_threadtypes y WHERE t.typeid = y.typeid
复制代码 查询论坛的主题,并显示版块名称:- SELECT * FROM 数据库名.cdb_threads t, 数据库名.cdb_forums f WHERE t.fid = f.fid
复制代码 如何调用版块简介- SELECT * FROM 数据库名.cdb_forums s,数据库名.cdb_forumfields f WHERE s.fid=f.fid
复制代码 从SS取Discuz!含有图片附件的最新主题- SELECT * , a.attachment AS attachment FROM cdb_threads t, cdb_attachments a, cdb_posts p WHERE t.tid = a.tid AND a.isimage =1 AND p.tid = t.tid AND p.first =1 GROUP BY t.tid ORDER BY t.dateline DESC
复制代码 读取论坛 某个用户所收藏的主题:- SELECT * FROM cdb_favorites f, cdb_members m, cdb_threads t WHERE f.uid = m.uid AND f.tid = t.tid
复制代码 调用论坛中每个主题调用一张图片的SQL:- SELECT a. * , t. * , count( DISTINCT a.tid )
- FROM cdb_attachments a, cdb_threads t
- WHERE a.tid = (
- SELECT t.tid
- FROM cdb_threads t
- WHERE t.attachment =2
- ORDER BY dateline DESC )
- GROUP BY a.tid
复制代码 查询论坛的分类信息
论坛的分类信息是要四表联查的,并且不能一次查出来,分两次,第一次是将主题表与主题类型有联查(数据显示一次)
第二步是查询分类信息的各个选项的值,查询出来后进行循环显示
注意:因为很复杂,具体应用时,要先理解清楚,把SQL在数据库中运行一遍,想好怎么写展示代码- SELECT * FROM cdb_threads t, cdb_threadtypes y WHERE t.sortid = y.typeid and t.tid=4
- select * from cdb_typeoptionvars v,cdb_typeoptions o where o.optionid=v.optionid and v.tid=4 and v.sortid=1
复制代码 如有其他需要请跟帖 |