Jump to content

Loading url of img from db


Sorrow

Recommended Posts

Hi everyone. I have a little problem when I try to load a image that the url is saved in a database. Here what I am doing. When you click on the link of one movie, it goes to moviereview.php?index=1 but in my database I have a field that has the link to the image but I cant seem to be able to load the image on the other page.It loads everything else but not the img.

 

<?php

include 'opendb.php';
$currIndex = $_GET['index'];
$query  = "SELECT * FROM reviews where m_index = $currIndex";
$result = mysql_query($query);


while($row = mysql_fetch_array($result, MYSQL_ASSOC))


{
    echo "<img src='{$row['m_Link']}'> ".

"{$row['m_Title']} <p>".
"{$row['m_Review']} <br> ";
}
mysql_close($con);


?>

Link to comment
https://forums.phpfreaks.com/topic/112795-loading-url-of-img-from-db/
Share on other sites

I always use heredoc strings for long multi-line block strings.

 

<?php
include 'opendb.php';

$currIndex = $_GET['index'];

$query  = "SELECT * FROM `reviews` WHERE `m_index` = '$currIndex'";
$result = mysql_query($query) or trigger_error(mysql_error()); // ALWAYS use error handling


while($row = mysql_fetch_array($result)) {
    echo <<<DBRow
        <img src={$row['m_Link']}>
{$row['m_Title']} <p>
{$row['m_Review']} <br>
    DBRow;
}
// No need for mysql_close(). PHP automatically terminates all open connections when the script ends.
?>

So you aren't going to post the generated source, then? It would be a lot easier for me to help you debug it if you did. Or you can just change it to something that is certain to work and see if it echos the link:

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
   echo $row['m_Link'] . "<br>";

 

If that code echoes the links than I'm pretty sure the problem is in the generated source somewhere.

It's called a "heredoc" string.

 

PHP reference: http://uk.php.net/types.string

 

However, I might have use it in-correctly. I don't usually use arrays with it.

 

<?php
include 'opendb.php';

$currIndex = $_GET['index'];

$query  = "SELECT * FROM `reviews` WHERE `m_index` = '$currIndex'";
$result = mysql_query($query) or trigger_error(mysql_error()); // ALWAYS use error handling


while($row = mysql_fetch_array($result)) {
    echo <<<DBRow
        <img src="{$row['m_Link']}">
{$row['m_Title']} <p>
{$row['m_Review']} <br>
    DBRow;
}
// No need for mysql_close(). PHP automatically terminates all open connections when the script ends.
?>

 

Give that a try.

 

EDIT: Yep, my first post was correct. Arrays should be enclosed in curly braces.

Because it echoes the string image link properly the database is working as expected and because the information after the img echo is being displayed, you know the echo is working. There is only one possibility that I can think of and that is that the generated html does not look like what you would expect it to. If it does, there must be a problem with your browser. In either case, it would be very helpful to see that generated code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.