0

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

 <?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

代码不起作用。对不起,但天哪,没有答案。

4

2 回答 2

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

因为我是一个好人,所以我把这个答案留给那些会被困在这样一个简单问题上的人。谢谢我。

于 2013-10-28T02:58:21.780 回答
-1

您的 Sql 查询错误:-

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

更正您的 Where 条件,一切都应该正常工作..

于 2013-10-23T04:18:42.297 回答