2014-08-30 42 views
-1

我以前问过这个问题,但没有答案,所以我再问一次,但这一次,我会更具体。 我有一个在线论坛,我从头开始创建php和mysql,我已经实现了图像上传部分命名图像的主题ID,从帖子表,现在我有问题显示图像拉名称以及来自图像表的扩展名并将其附加到要显示的主题ID。现在,这是用于显示主题(viewtopic.php)php/mysql如何在网上论坛中显示图片

$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; 

} 
回波($体)后

现在如果我运行此查询的代码段;

$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; ?>" > 

帮助我,我如何得到图像显示?

回答

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