0

这是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>

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

4

2 回答 2

0

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

于 2013-11-03T21:12:51.943 回答
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 
    }   


?>
于 2013-11-03T22:18:53.217 回答