Display Images Using PHP/mySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mo
Forum Newbie
Posts: 21
Joined: Thu Nov 06, 2003 7:21 am

Display Images Using PHP/mySQL

Post by Mo »

With the code below I can display an image located in the /public_html/images/ directory.

1) How can I display this image as thumbnail?
2) How can I make the thumbnail link to the origional image or another page?
3) How can I put this PHP file in any folder and always display the image in the /public_html/images/ folder?

Code: Select all

<?php 
  // Set the variables for the database access: 
  $host="localhost"; 
  $username=""; 
  $password=""; 
  $database="Photos"; 
  $table="Table_1"; 

  // Connect to database and go to correct database 
  mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
  mysql_select_db ($database) or die ("<b>Database $database does not exist</b>"); 

  $query = "SELECT * from $table"; 
  $result = mysql_query($query) or exit(); 
  $row = mysql_fetch_row($result); 

  mysql_close(); 
  ?> 

  <img src="images/<?php echo($row[2]); ?>">
Thanks
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

1)
Might be interesting: viewtopic.php?t=12215
Basicly, easiest (?) way would be to use GD.

2+3) You need to change the print outs.
<img src="images/... = current_dir/images/...
<img src="/images/... = home_directory/images/...

Adding the link is similar to the above:
<a href="/images/<?php echo($row[2]); ?>">[display thumnail image here]</a>
Post Reply