无法显示图像

时间:2013-11-03 21:08:05

标签: php

这是PHP代码:

<?php    

$dbhost = 'localhost';    
$dbuser = 'root';    
$dbpass = '';  
$dbname = 'moviefone';    
$con = mysql_connect($dbhost, $dbuser, $dbpass);  
mysql_select_db($dbname, $con);    

// Check connection    
if (mysqli_connect_errno()) {  
    echo "Failed to connect to MySQL: " . mysqli_connect_error();    
}    

$data = mysql_query("SELECT * FROM new_hindi LIMIT 4") or die(mysql_error());    $info = NULL;   

while($row = mysql_fetch_array( $data ))    
{    
    $info = $row ;    
};    


?>

HTML:

<div class="sub-column1">
    <a class="new_movies" href="#"><span>New</span></a> <a href="#"><img src=
    "%3C?php%20echo%20$info[">" width="140" height="200" class="new-img"
    /&gt;</a> <a class="img_titles" href="#"><?php echo $info["title"];?></a>
    <a class="new_english" href="#"><span>New</span></a>
</div>

我无法显示图像和标题。它显示没有错误,但图像是空白的。

2 个答案:

答案 0 :(得分:0)

问题是您的$info数组不在范围内。 您必须将循环中的值分配给另一个变量,或将信息推送到范围内的另一个数组。

答案 1 :(得分:0)

$info不在您使用它的范围内。您需要将HTML放入while()

常见警告...请不要使用已折旧的此类型的mysql连接,而是使用PDO

<?php    

    $dbhost = 'localhost';    
    $dbuser = 'root';    
    $dbpass = '';  
    $dbname = 'moviefone';    
    $con = mysql_connect($dbhost, $dbuser, $dbpass);  
    mysql_select_db($dbname, $con);    

    // Check connection    
    if (mysqli_connect_errno()) {  
        echo "Failed to connect to MySQL: " . mysqli_connect_error();    
    }    

    $data = mysql_query("SELECT * FROM new_hindi LIMIT 4") or die(mysql_error());   

    while($row = mysql_fetch_array( $data )){    ?>

        <div class="sub-column1">
            <a class="new_movies" href="#"><span>New</span></a> <a href="#"><img src="<?php echo $row['image'];?>" width="140" height="200" class="new-img" /></a> <a class="img_titles" href="#"><?php echo $row["title"];?></a>
            <a class="new_english" href="#"><span>New</span></a>
        </div>      

        <?php 
    }   


?>