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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.