【问题标题】:php/mysql How to display images in an online forumphp/mysql 如何在在线论坛中显示图像
【发布时间】:2014-08-30 13:19:23
【问题描述】:

我以前问过这个问题,但没有得到答案,所以我再问一次,但这次我会更具体。 我有一个使用 php 和 mysql 从头开始​​创建的在线论坛,我已经实现了通过主题 id 从帖子表中命名图像的图像上传部分,现在我在通过拉取名称来显示图像时遇到问题和图像表的扩展并将其附加到要显示的主题 ID。现在这是显示主题的代码 sn-p (viewtopic.php)

$sql = "
SELECT SQL_CALC_FOUND_ROWS p.id
                         , p.subject
                         , p.body
                         , p.date_posted
                         , p.date_updated
                         , u.name as author
                         , u.id as author_id
                         , u.signature as sig
                         , c.count as postcount
                         , p.forum_id as forum_id
                         , f.forum_moderator as 'mod'
                         , p.update_id
                         , u2.name as updated_by 
                      FROM forum_forum f 
                      JOIN forum_posts p 
                        ON f.id = p.forum_id 
                      JOIN forum_users u 
                        ON u.id = p.author_id 
                      LEFT 
                      JOIN forum_users u2 
                        ON u2.id = p.update_id 
                      LEFT 
                      JOIN forum_postcount c 
                        ON u.id = c.user_id 
                     WHERE $topicid IN (p.topic_id,p.id) 
                     ORDER 
                        BY p.topic_id
                         , p.date_posted 
                     LIMIT $start,$limit;
                     ";
$result = mysqli_query($sql, $conn)
or die(mysql_error() . "<br>" . $sql);
while ($row = mysqli_fecth_array($result) )
{
echo "<p>($body) . "</p>";
  echo $sig;

}

如果我运行这个查询,现在在 echo ($body) 之后;

$sql = "SELECT * FROM images WHERE name = '$name'"; 
$result = mysqli_query($sql) or die('Could not SELECT image data ' . mysql_error());
while ($therow = mysql_fetch_array($result))
{
$image_name = $therow["name"] ;
$ext = $therow["extension"];
}

?>
<img src="images/<?php echo $image_name.$ext;  ?>" >

帮帮我,如何让图像显示?

【问题讨论】:

    标签: php mysql image upload


    【解决方案1】:

    尝试替换这个:

    while ($row = mysqli_fecth_array($result) )
    {
        echo "<p>($body) . "</p>";
        echo $sig;
    }
    

    while ($row = mysqli_fetch_array($result) )
    {
        echo "<p>($body)" . "</p>";
        echo $sig;
    } 
    

    还有这个

    $sql = "SELECT * FROM images WHERE name = '$name'"; 
    $result = mysqli_query($sql) or die('Could not SELECT image data ' . mysql_error());
    while ($therow = mysql_fetch_array($result))
    {
        $image_name = $therow["name"] ;
        $ext = $therow["extension"];
    }
    ?>
    

    $sql = "SELECT * FROM images WHERE name = '$name'"; 
    $result = mysqli_query($sql) or die('Could not SELECT image data ' . mysql_error());
    while ($therow = mysqli_fetch_array($result))
    {
        $image_name = $therow["name"];
        $ext = $therow["extension"];
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 2012-10-28
      • 2019-07-16
      • 2011-08-26
      • 1970-01-01
      • 2022-07-27
      • 1970-01-01
      相关资源
      最近更新 更多