Discuz!官方免费开源建站系统

 找回密码
 立即注册
搜索

[已答复] 论坛中每个主题调用一张图片的SQL 报错

[复制链接]
esys 发表于 2009-11-6 10:25:59 | 显示全部楼层 |阅读模式
请朋友指教
调用论坛中每个主题调用一张图片的SQL:
  1. SELECT a. * , t. * , count( DISTINCT a.tid ) FROM eucom_bbs.cdb_attachments a, eucom_bbs.cdb_threads t WHERE a.tid = ( SELECT t.tid FROM eucom_bbs.cdb_threads t WHERE t.attachment =2 ORDER BY dateline DESC ) GROUP BY a.tid
复制代码
创建模块论坛附件使用上面的调用报错

SupeSite info: MySQL Query Error

User: admin
Time: 2009-11-6 9:49am
Script: /57eu.php

SQL: SELECT a. * , t. * , count( DISTINCT a.tid ) FROM eucom_bbs.[Table]attachments a, eucom_bbs.[Table]threads t WHERE a.tid = ( SELECT t.tid FROM eucom_bbs.[Table]threads t WHERE t.attachment =2 ORDER BY dateline DESC ) GROUP BY a.tid LIMIT 0,6
Error: Subquery returns more than 1 row
Errno.: 1242
回复

使用道具 举报

lidq.jingwu 发表于 2009-11-6 10:36:07 | 显示全部楼层
1# esys


    用下面的SQL试一下:
  1. SELECT a. * , t. * , count( DISTINCT a.tid ) FROM eucom_bbs.cdb_attachments a, eucom_bbs.cdb_threads t WHERE a.tid IN ( SELECT t.tid FROM eucom_bbs.cdb_threads t WHERE t.attachment =2 ORDER BY dateline DESC ) GROUP BY a.tid
复制代码
回复

使用道具 举报

benba 发表于 2009-11-6 10:38:18 | 显示全部楼层
回复

使用道具 举报

 楼主| esys 发表于 2009-11-6 10:46:07 | 显示全部楼层
谢谢 楼上的 老版和 benba  马上测试
回复

使用道具 举报

 楼主| esys 发表于 2009-11-6 10:56:24 | 显示全部楼层
  1. <!--{block name="bbsattachment" parameter="sql/SELECT%20a.%20%2A%20%2C%20t.%20%2A%20%2C%20count%28%20DISTINCT%20a.tid%20%29%20FROM%20eucom_bbs.cdb_attachments%20a%2C%20eucom_bbs.cdb_threads%20t%20WHERE%20a.tid%20IN%20%28%20SELECT%20t.tid%20FROM%20eucom_bbs.cdb_threads%20t%20WHERE%20t.attachment%20%3D2%20ORDER%20BY%20dateline%20DESC%20%29%20GROUP%20BY%20a.tid/limit/0,6/cachetime/900/subjectlen/42/cachename/bbshuandeng01/tpl/data"}--><!--论坛图片-->
  2. <pre>
  3. <!--{eval print_r($_SBLOCK['bbshuandeng01']);}-->
  4. </pre>
  5. <!--{eval exit;}-->
复制代码
可以打印出来了,谢谢!!!
回复

使用道具 举报

 楼主| esys 发表于 2009-11-6 12:41:15 | 显示全部楼层
图片 地址$value[attachment] 或$value[attachment]/$value[filename]
都不对,应该怎么写?
回复

使用道具 举报

neol123 发表于 2009-11-6 13:01:11 | 显示全部楼层
和我当初的一样

回复

使用道具 举报

 楼主| esys 发表于 2009-11-6 15:10:04 | 显示全部楼层
请朋友帮帮我谢谢   图片地址怎么调用啊
  1. SELECT a. * , t. * , count( DISTINCT a.tid ) FROM eucom_bbs.cdb_attachments a, eucom_bbs.cdb_threads t WHERE a.tid IN ( SELECT t.tid FROM eucom_bbs.cdb_threads t WHERE t.attachment =2 ORDER BY dateline DESC ) GROUP BY a.tid
复制代码
回复

使用道具 举报

lidq.jingwu 发表于 2009-11-6 15:49:25 | 显示全部楼层
6# esys


    将你写的展示代码及打印的数据发上来看一下。
回复

使用道具 举报

 楼主| esys 发表于 2009-11-6 16:04:43 | 显示全部楼层
本帖最后由 esys 于 2009-11-6 16:06 编辑
  1. 版主的方法

  2. 正确为:
  3. SELECT a. * , t. * , count( DISTINCT a.tid ) FROM eucom_bbs.cdb_attachments a, eucom_bbs.cdb_threads t WHERE a.tid IN ( SELECT t.tid FROM eucom_bbs.cdb_threads t WHERE t.attachment =2 ORDER BY dateline DESC ) GROUP BY a.tid

  4. <!--{block name="bbsattachment" parameter="sql/SELECT%20a.%20%2A%20%2C%20t.%20%2A%20%2C%20count%28%20DISTINCT%20a.tid%20%29%20FROM%20eucom_bbs.cdb_attachments%20a%2C%20eucom_bbs.cdb_threads%20t%20WHERE%20a.tid%20IN%20%28%20SELECT%20t.tid%20FROM%20eucom_bbs.cdb_threads%20t%20WHERE%20t.attachment%20%3D2%20ORDER%20BY%20dateline%20DESC%20%29%20GROUP%20BY%20a.tid/limit/0,6/cachetime/900/subjectlen/42/cachename/bbshuandeng01/tpl/data"}--><!--论坛图片-->
  5. <!--{loop $_SBLOCK['bbshuandeng01'] $value}-->
  6. <li><a target="_blank" href="$value[url]"><img alt="$value[subjectall]" src="$value[attachment]" /><p>$value[subject]</p></a></li>
  7. <!--{/loop}-->
复制代码
  1. Array
  2. (
  3.     [0] => Array
  4.         (
  5.             [aid] => 11
  6.             [tid] => 12
  7.             [pid] => 37
  8.             [width] => 600
  9.             [dateline] => 1255701859
  10.             [readperm] => 0
  11.             [price] => 0
  12.             [filename] => W020090910552797477021.jpg
  13.             [filetype] => application/octet-stream
  14.             [filesize] => 37389
  15.             [attachment] => http://bbs.57eu.com/attachments/0
  16.             [downloads] => 2
  17.             [isimage] => 1
  18.             [uid] => 1
  19.             [thumb] => 0
  20.             [remote] => 0
  21.             [fid] => 2
  22.             [iconid] => 0
  23.             [typeid] => 0
  24.             [sortid] => 0
  25.             [author] => admin
  26.             [authorid] => 1
  27.             [subject] => Discuz!7.1 新特性——Manyou应用的开启
  28.             [lastpost] => 1255701859
  29.             [lastposter] => admin
  30.             [views] => 7
  31.             [replies] => 0
  32.             [displayorder] => 0
  33.             [highlight] => 0
  34.             [digest] => 0
  35.             [rate] => 0
  36.             [special] => 0
  37.             [moderated] => 0
  38.             [closed] => 0
  39.             [itemid] => 0
  40.             [supe_pushstatus] => 1
  41.             [recommends] => 0
  42.             [recommend_add] => 0
  43.             [recommend_sub] => 0
  44.             [heats] => 0
  45.             [blog] => 0
  46.             [count( DISTINCT a.tid )] => 1
  47.             [subjectall] => Discuz!7.1 新特性——Manyou应用的开启
  48.             [a_thumbfile] => http://bbs.57eu.com/attachments/0
  49.             [a_attachment] => http://bbs.57eu.com/attachments/0
  50.             [url] => http://bbs.57eu.com/viewthread.php?tid=12
  51.         )

  52.     [1] => Array
  53.         (
  54.             [aid] => 12
  55.             [tid] => 17
  56.             [pid] => 38
  57.             [width] => 800
  58.             [dateline] => 1256826472
  59.             [readperm] => 0
  60.             [price] => 0
  61.             [filename] => 2009022523383698741.jpg
  62.             [filetype] => application/octet-stream
  63.             [filesize] => 88385
  64.             [attachment] => http://bbs.57eu.com/attachments/2
  65.             [downloads] => 0
  66.             [isimage] => 1
  67.             [uid] => 1
  68.             [thumb] => 0
  69.             [remote] => 0
  70.             [fid] => 100
  71.             [iconid] => 0
  72.             [typeid] => 0
  73.             [sortid] => 0
  74.             [author] => admin
  75.             [authorid] => 1
  76.             [subject] => 大连女骑警 飒爽英姿
  77.             [lastpost] => 1256826472
  78.             [lastposter] => admin
  79.             [views] => 11
  80.             [replies] => 0
  81.             [displayorder] => 0
  82.             [highlight] => 0
  83.             [digest] => 0
  84.             [rate] => 0
  85.             [special] => 0
  86.             [moderated] => 0
  87.             [closed] => 0
  88.             [itemid] => 0
  89.             [supe_pushstatus] => 0
  90.             [recommends] => 0
  91.             [recommend_add] => 0
  92.             [recommend_sub] => 0
  93.             [heats] => 0
  94.             [blog] => 0
  95.             [count( DISTINCT a.tid )] => 1
  96.             [subjectall] => 大连女骑警 飒爽英姿
  97.             [a_thumbfile] => http://bbs.57eu.com/attachments/2
  98.             [a_attachment] => http://bbs.57eu.com/attachments/2
  99.             [url] => http://bbs.57eu.com/viewthread.php?tid=17
  100.         )

  101.     [2] => Array
  102.         (
  103.             [aid] => 14
  104.             [tid] => 19
  105.             [pid] => 39
  106.             [width] => 505
  107.             [dateline] => 1256918752
  108.             [readperm] => 0
  109.             [price] => 0
  110.             [filename] => 2009109203934.jpg
  111.             [filetype] => application/octet-stream
  112.             [filesize] => 59608
  113.             [attachment] => http://bbs.57eu.com/attachments/2
  114.             [downloads] => 0
  115.             [isimage] => 1
  116.             [uid] => 1
  117.             [thumb] => 1
  118.             [remote] => 0
  119.             [fid] => 67
  120.             [iconid] => 0
  121.             [typeid] => 0
  122.             [sortid] => 0
  123.             [author] => admin
  124.             [authorid] => 1
  125.             [subject] => 大连美女孟幻狐狸(写真)
  126.             [lastpost] => 1256918752
  127.             [lastposter] => admin
  128.             [views] => 1
  129.             [replies] => 0
  130.             [displayorder] => 0
  131.             [highlight] => 0
  132.             [digest] => 0
  133.             [rate] => 0
  134.             [special] => 0
  135.             [moderated] => 0
  136.             [closed] => 0
  137.             [itemid] => 0
  138.             [supe_pushstatus] => 0
  139.             [recommends] => 0
  140.             [recommend_add] => 0
  141.             [recommend_sub] => 0
  142.             [heats] => 0
  143.             [blog] => 0
  144.             [count( DISTINCT a.tid )] => 1
  145.             [subjectall] => 大连美女孟幻狐狸(写真)
  146.             [a_thumbfile] => http://bbs.57eu.com/attachments/2
  147.             [a_attachment] => http://bbs.57eu.com/attachments/2
  148.             [url] => http://bbs.57eu.com/viewthread.php?tid=19
  149.         )

  150.     [3] => Array
  151.         (
  152.             [aid] => 49
  153.             [tid] => 21
  154.             [pid] => 40
  155.             [width] => 533
  156.             [dateline] => 1257469263
  157.             [readperm] => 0
  158.             [price] => 0
  159.             [filename] => 2009109211432.jpg
  160.             [filetype] => application/octet-stream
  161.             [filesize] => 57907
  162.             [attachment] => http://bbs.57eu.com/attachments/0
  163.             [downloads] => 0
  164.             [isimage] => 1
  165.             [uid] => 1
  166.             [thumb] => 0
  167.             [remote] => 0
  168.             [fid] => 132
  169.             [iconid] => 0
  170.             [typeid] => 0
  171.             [sortid] => 0
  172.             [author] => admin
  173.             [authorid] => 1
  174.             [subject] => 大连老工业基地率先实现全面振兴的新机遇
  175.             [lastpost] => 1257469263
  176.             [lastposter] => admin
  177.             [views] => 1
  178.             [replies] => 0
  179.             [displayorder] => 0
  180.             [highlight] => 0
  181.             [digest] => 3
  182.             [rate] => 0
  183.             [special] => 0
  184.             [moderated] => 1
  185.             [closed] => 0
  186.             [itemid] => 0
  187.             [supe_pushstatus] => 1
  188.             [recommends] => 0
  189.             [recommend_add] => 0
  190.             [recommend_sub] => 0
  191.             [heats] => 0
  192.             [blog] => 0
  193.             [count( DISTINCT a.tid )] => 1
  194.             [subjectall] => 大连老工业基地率先实现全面振兴的新机遇
  195.             [a_thumbfile] => http://bbs.57eu.com/attachments/0
  196.             [a_attachment] => http://bbs.57eu.com/attachments/0
  197.             [url] => http://bbs.57eu.com/viewthread.php?tid=21
  198.         )

  199. )
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-9-16 20:53 , Processed in 0.128854 second(s), 14 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表