Page 1 of 1

Display Images Using PHP/mySQL

Posted: Thu Nov 06, 2003 12:02 pm
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

Posted: Thu Nov 06, 2003 12:07 pm
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>