php / mysql如何在在线论坛中显示图像

时间:2014-08-30 13:19:24

标签: php mysql image upload

我之前问过这个问题,但没有得到答案,所以我再次问它,但这一次,我会更具体。 我有一个在线论坛,我从头开始用php和mysql创建,我实现了图像上传部分命名图像的主题ID,从posts表,现在我有问题显示图像通过拉取名称和图像表中的扩展名并将其附加到要显示的主题ID。现在这是显示主题的代码片段(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;  ?>" >

帮助我,我如何才能显示图像?

1 个答案:

答案 0 :(得分:0)

尝试替换此:

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"];
}
?>