0

This is the PHP code:

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


?>

And the 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>

I can not display the image and the title. It's showing no errors but the image is blank.

Loke Cool
  • 35
  • 7
  • 2
    Line breaks and readable code are your friend when asking questions. – Fluffeh Nov 03 '13 at 21:10
  • Please don't use `mysql_*` functions anymore, they are deprecated. See [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for details. Instead you should learn about [prepared statements](http://bobby-tables.com/php.html) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you. If you pick PDO, [here is a good tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – Marcel Korpel Nov 03 '13 at 21:10
  • could you post your full code? – waka-waka-waka Nov 03 '13 at 21:11

2 Answers2

0

The problem is that your $info array is not in scope. You have to assign the values in your loop to another variable or push info to another array in scope.

puelo
  • 5,464
  • 2
  • 34
  • 62
0

$info was not in scope where you were using it. You need to put the HTML into the while()

Usual warnings... please don't use this type of mysql connection it has been depreciated, use PDO instead.

<?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 
    }   


?>
Chris
  • 5,516
  • 1
  • 26
  • 30
  • You may need to change `$row['image']` to match the name you have given the image column in the database, but it should work provided the query is returning results – Chris Nov 03 '13 at 22:41
  • well i have got it worked but i want four images to be displayed but only one image is repeating in four different place. – Loke Cool Nov 03 '13 at 22:50
  • Are you sure that the data being selected doesn't have the same image each time. Try putting `print_r($row);` in the `while($row = mysql_fetch_array( $data )`.... – Chris Nov 04 '13 at 09:28