Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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!

Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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?


Reply With Quote
  #4 (permalink)  
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.



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:02 AM.


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