Jump to content

PHP Image output


diddyd

Recommended Posts

Hello There,

 

I have been trying to get my page going for some time. I have managed to setup my database on mysql. I have managed to create myself a few pages that look how I want and do what I want. I have managed to get the data I want into my database. Where I am struggling big time is to find some way to get the images that I have gotten into my database back out again with a php page. I have managed to do a dynamic drop down, from one of the tables, but when I bring back the image files I get the binary, or a readout of the file. (I have a .gpx file as well as a load of .jpg files). The code I have managed so far is below, does anyone feel inclined to help me get a little further with this?

 

I am new to HTML and to PHP, although databases are perhaps a little more familiar to me. I would like if possible to show the images in the lower half of the same page that the drop down is on, although if this is not possible then please let me know.

 

<?php 
require_once 'login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);

if (!$db_server) die("unable to connect to MySQL: " . mysql_error());

//connecting to the database.
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());

// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&&$select!=""){
$select=$_GET['select'];
}
?>
<body>
<form method="POST" action="predroptest.php">
Hills :
<select name="selecthill">
<option value="">--- Select Hill---</option>
<?

// Get records from database (table "Hills").
$list=mysql_query("select ID, Hill from Hills order by Hill");

// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['ID']; ?>" <? if($row_list['ID']==$select){ echo "selected"; } ?>><? echo $row_list['Hill']; ?></option>
<?
// End while loop.
}
?>
</select> 
<input type="submit" name="Submit" value="Select" />
</form>
<hr>
<p>
<?
// Get records from database (table "Hills").

$select1=$_POST['selecthill'];

$query="SELECT * FROM Objects Where Data_ID='$select1'";

$result=mysql_query($query);

$num=mysql_numrows($result);

echo "<b><center>Hill Info</center></b><br><br>";

$i=0;
while ($i < $num) {

$Data_ID=mysql_result($result,$i,"Data_ID");
$Object=mysql_result($result,$i,"Object");
$Type=mysql_result($result,$i,"Type");
$Description=mysql_result($result,$i,"Description");

header('Content-type: image/jpg');

echo "<b>$Data_ID<br>$Object<br>$Type<br>$Description<hr><br>";

$i++;
}

mysql_close();
?>

</p>
</body>

 

Thanks very much for the help

 

Diana Tracy

 

www.up-a-hill.me.uk

Link to comment
Share on other sites

A better way is just to store the name of the image in the database and possibly the path to the stored image, and use your script to upload the image to a directory on your web server where it will be displayed from.

 

there is a sample script on how to do that in this post which also gives you resize options

 

http://www.phpfreaks.com/forums/index.php?topic=333194.0

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.