Sorrow Posted July 1, 2008 Share Posted July 1, 2008 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); ?> Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 What do you mean by "it loads everything else?" Is there a bad image box or is it not getting written to the html at all? Can you post the generated source code? Quote Link to comment Share on other sites More sharing options...
Sorrow Posted July 1, 2008 Author Share Posted July 1, 2008 It is not getting written to html because their is no broken image box but it displays the movie title and the review but nothing related to a image. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 I don't think that is possible with that code. I am really curious to see the generated source, now. Quote Link to comment Share on other sites More sharing options...
Sorrow Posted July 1, 2008 Author Share Posted July 1, 2008 I know this code is not working thats why I m asking how to do it lol Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 1, 2008 Share Posted July 1, 2008 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. ?> Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 1, 2008 Share Posted July 1, 2008 Just to be sure, are you positive that the image path's are correct? Have you tried linking directly to one from the browser? Quote Link to comment Share on other sites More sharing options...
Sorrow Posted July 1, 2008 Author Share Posted July 1, 2008 Lemmin : yes it echoes the link properly Wolphie : I am not sure what to do with your <<<DBRow what is that. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 1, 2008 Share Posted July 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
Sorrow Posted July 4, 2008 Author Share Posted July 4, 2008 what exactly do you mean by the generated code??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.