显示主题帖子,帖子,图片的评论

时间:2013-10-22 23:18:26

标签: php mysql

好吧,我正在尝试显示与其链接的回复的图片。我找到了这段代码,但结果是空的,只有列标题名称出现。有谁知道为什么。

 <?php

   include 'connect.php';





        $sql2 = "SELECT * FROM `images` WHERE `mid`";
        $res2 = mysql_query($sql2) or die(mysql_error());
        if(mysql_num_rows($res2) == 0){
            echo "There are no topics in this forum, <a  href=\"./index.php?act=create&     id=".$row['id']."\">click here</a> to create a topic!\n";
        }else {
            echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\">\n";
            echo "<tr><td colspan=\"4\" align=\"right\"><a  href=\"./index.php?act=create&id=".$row['mid']."\">create a topic</a></td></tr>\n";
            echo "<tr align=\"center\"><td class=\"forum_header\">Title</td><td class=\"forum_header\">User</td><td class=\"forum_header\">Date Created</td><td class=\"forum_header\">Replies</td></tr>\n";
            while($row2 = mysql_fetch_assoc($res2)){
                $sql3 = "SELECT * FROM `reply` WHERE `mid`";
                $res3 = mysql_query($sql3) or die(mysql_error());
                $row3 = mysql_fetch_assoc($res3);
                echo "<tr align=\"center\"><td><a href=\"./index.php?act=topic&id=".$row2['mid']."\">".s($row2['name'])."</a></td><td>".uid($row2['who'])."</td><td>".$row2['date']."</td><td>".$row3[reply']."</td></tr>\n";
            }
            echo "</table>\n";
        }

    }
}

 ?>

Name是mysql中图像或路径的名称。

表格结构

TABLE Header
username
 id
who
 where

Table images
message
 name
mid  - id that auto increments when image is loaded
id
content

Table reply
 mid  id that is taken from images mid to relate image to reply.
reply
id ----this is only for an id for a reply that is auto increment

代码不起作用。对不起,但没有回答。

2 个答案:

答案 0 :(得分:0)

好。我很失望很多人都无法得到这个简单的答案。答案很简单。

    SELECT images.name, GROUP_CONCAT(  'reply.reply'
  SEPARATOR  "|" ) 
  FROM images, reply
  WHERE reply.mid = images.mid
  OR reply.mid = reply.reply
   GROUP BY images.mid

因为我是一个好人,所以我会把这个答案留给那些会陷入如此简单问题的人。谢谢。

答案 1 :(得分:-1)

您的Sql查询错误: -

  $sql2 = "SELECT * FROM `images` WHERE `mid`";
                                   ^
  $sql3 = "SELECT * FROM `reply` WHERE `mid`";
                                   ^

纠正你的Where条件一切都应该有效..