Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2006, 01:28 PM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying images stored in MySQL through in PHP

Hiya!

I was advised to store image paths within databases, instead of storing within a field the image itself.

I am at the stage where I want to make use of that image path and display an image in a webpage using PHP.

I have two scripts. This is the first:

Code:
<?php
 include ('common_db.php');


         $link_id = db_connect();


    $query = "SELECT * FROM Article";
    $result = mysql_query($query) or die("Invalid query: " .     mysql_error());

?>



<h1>News Stories</h1>

<?php

    while ($row = mysql_fetch_array($result)) {

?>

<p><a href="ViewArticle.php?action=Article&ID=<?php echo $row['ArticleID'];?>"><?php echo $row['ArticleTitle'];?></a></p>


<?php
 }
?>
When you click the link (which is the title of the story), you go to script 2:


Code:
<?php
 include ('common_db.php');


         $link_id = db_connect();

$query = "SELECT * FROM Article, Image WHERE Article.ArticleImage = Image.ImageID AND ArticleID = '" . $_GET['ID'] . "'";


$result = mysql_query($query) or die("Invalid query: " . mysql_error());





      $row = mysql_fetch_array($result)
?>


                  <p><?php echo $row['ArticleTitle']; ?></p>
                  <p><?php echo $row['ArticleDate']; ?></p>
                  <p><?php echo $row['ImageLoc']; ?></p>
                  <p><?php echo $row['ArticleEntry']; ?></p>

                  <p><a href="ArticleLinks.php">back</a></p>
The field "ImageLoc" is the path to image stored on the server.

Only problem is, the actual path is displayed, not the image.

What am I doing wrong?

Any help appreciated!

 
Old May 1st, 2006, 01:43 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Code:
                  <p><?php echo $row['ArticleTitle']; ?></p>
                  <p><?php echo $row['ArticleDate']; ?></p>
                  <p><img src="<?php echo $row['ImageLoc']; ?>"></p>
                  <p><?php echo $row['ArticleEntry']; ?></p>

                  <p><a href="ArticleLinks.php">back</a></p>
Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html
 
Old May 1st, 2006, 02:13 PM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hiya!

Thanks very much! I still have a problem though. Damn!
When I refresh the browser the graphic icon appears then disappears. No image is displayed.

The location is correct because in the few seconds it appears I checked the properties and the path is correct. I also checked that the image is in the directory.

I checked firefox too to make sure images are turned on in "options".

Any ideas?


 
Old May 2nd, 2006, 04:55 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Aah hah, twas nothing more than a path error in PHPMyAdmin.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying Information Php/mysql TheSchwa MySQL 1 November 12th, 2007 04:14 PM
HELP - Displaying Images from mysql timmaher Beginning PHP 5 January 26th, 2005 03:09 PM
Displaying images stored in a DB on a Web Form Trevor Miles ASP.NET 1.0 and 1.1 Basics 0 January 7th, 2005 04:14 AM
displaying images from mySql DB in html cmcmillan.schillers Beginning PHP 1 October 5th, 2004 03:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.