+ -
当前位置:首页 → 问答吧 → 数据库查询语句写法继续求助【有图】

数据库查询语句写法继续求助【有图】

时间:2011-08-06

来源:互联网

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />
图示为数据表pw_forums的信息,目前需要补充语句段A和语句段B,代码如何写呢?

详见代码中的疑惑,求助论坛高人解决。

-----------------------------------
$fltshow = ''; //定义$fltshow变量为空
语句段A…… //如何在表pw_forums中查询符合pf.dirname = 'bbs2'条件的分类版块的fid数组,图中即为7和8。
语句段B…… //如何在表pw_forums中通过刚获得的分类版块pf.fid数组(对应普通版块的pf.fup),进一步查出相应的普通版块fid数组(图中即为9、11、18、13、14)并赋给变量$justshow
if(!empty($justshow)) //如果$justshow变量非空
$fltshow = "AND pt.fid IN ($justshow)"; //插入到首页排行榜调用语句where某条件后
-----------------------------------

-----------------------------------

$fltshow = '';
$justshow=$db->query("SELECT fid FROM pw_forums M WHERE EXISTS(SELECT 1 FROM pw_forums N WHERE N.dirname='bbs2' AND N.fid=M.fup)");
if(!empty($justshow)){
$fltshow = "AND pt.fid IN ($justshow)";
}

在大侠jinguanding的指导下,采用上述代码在测试过程中提示错误如图。

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />

发现变量$justshow值为Resource id #23,而变量$fltshow则对应为AND pt.fid IN (Resource id #23)
实际上,最终希望实现的是$fltshow = "AND pt.fid IN (9,11,18,13,14)";

该如何修改完善呢?

[ 本帖最后由 sjkstudy 于 2011-8-6 13:30 编辑 ]

作者: sjkstudy   发布时间: 2011-08-06

好乱啊 ..

作者: zty5984   发布时间: 2011-08-06

SELECT fid FROM pw_forums M WHERE EXISTS(SELECT 1 FROM pw_forums N WHERE N.dirname='bbs2' AND N.fid=M.fup)

这句是否不适用?

版块fid 为9,11,18,13,14这多行对应的dirname是空的噢。

作者: sjkstudy   发布时间: 2011-08-06