I have a mysql table that has id, name, type, size, content, and link. I have pages download.php and showimage.php. I want the link to affect the image so when the user clicks it sends them their. I only created showimage.php cause I had ran out of options on how to link and was hoping i could extract the link somehow from download.php. Heres the code for both.

Download.php

<?php
include 'config3.php';
include 'opendb.php';

$query = "SELECT name, type, size, content, link FROM `upload` ORDER BY RAND() LIMIT 1";

$result = mysql_query($query) or die('Error, query failed'); 
while($row= mysql_fetch_array($result)){
$content = $row['content']; 
$size= $row['size']; 
$type= $row['type'];
 $link= $row['link'];
header('Content-type: $type');
echo $content;
}
include 'closedb.php'; 
?>

Showimage.php

<html>
<head>
<title>Image Test</title>
</head>
 
<body>
<h1>Displaying image from database</h1>
 
<a href="download.php"><img src="download.php" height="250" width="250"/></a> </body>
 
</html>

Download.php code above only shows the image. I've tried playing with download.php to echo "<a href='".$link."'/><img src='".$content."' /></a>"; but when i do this the image turns into a huge jarbled mess. Any suggestions?

The tutorial you gave shows how to present the image.. which I'm already doing with the code above.. My problem is that the table also has a column for links. When the user clicks on the picture i want it to send the user to the appropriate address.

I figured it out.. after banging my head on the keyboard for 12 hrs... lol. I'll post the code for the sake of all the broken computer equipment out there. Here's it is.

Showimage.php

<?php
include 'config3.php';
include 'opendb.php';

$query = "SELECT id, name, type, size, content, link " .
         "FROM  `upload` ORDER BY RAND() LIMIT 1";
		 $result = mysql_query($query) or die('Error, query failed');
while($row= mysql_fetch_array($result)){
	$content = $row['content'];
		$id= $row['id'];
	$size= $row['size'];
	$type= $row['type'];
	$link= $row['link'];
	}
?>
<html>
<head>
<title>Image Test</title>
</head>
 
<body>
<h1>Displaying image from database</h1>
<a href="<?php echo $link?>" />
<img src="download.php?id=<?php echo $id?>" height="250" width="250"/>
</a>
</body>
 
</html>

Download.php

<?php
include 'config3.php';
include 'opendb.php';

if(isset($_GET['id'])){
 $id=$_GET['id']; 
}else{
echo 'did not get id'; 
}

$query = "SELECT id, name, type, size, content, link " .
         "FROM `upload` WHERE id='$id'";

$result = mysql_query($query) or die('Error, query failed');
while($row= mysql_fetch_array($result)){
	$content = $row['content'];
		$id= $row['id'];
	$size= $row['size'];
	$type= $row['type'];
	$link= $row['link'];


header('Content-type: $type'); 
echo $content;
exit();
}


include 'closedb.php'; 


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.