Si Petch wrote:
Hi,
I want to set up a search facility on my website an wonder if MySql is the
way to do it. Heres the basics of the website:
A database containing information for a set of villas with details such as:
villa name; location; number of bedrooms; description; prices etc.... Is it
possible to include references to pictures in the database and then prouce
each villas own webpage simply from the information in the table into some
sort of template?
[snip]
Doing the pictures is pretty easy from PHP.
Create a BLOB column of the appropriate size (MEDIUM will probably work
fine). Have a unique key for the picture (if there's only one picture
per property, putting the blob in the property table will work fine,
otherwise have a table that links properties to pictures and use the key
of the picture table).
Have PHP generate <img> tags that look like this:
<img src="getpicture.php?id=27">
Obviously with the correct id value.
Write a getpicture.php script that SELECTs the appropriate blob and
returns it. If you limit yourself to one type of picture (e.g. JPEG),
this is all you need. If you have multiple picture types (e.g. JPEG,
GIF, PNG), you'll also have to store the picture's MIME type with the
picture.
The getpicture.php script has to set the Content-Type header to the
appropriate MIME type then just "echo" the blob.
HTH,
- Mark
P.S. It's short so I'll post it. This is my getphoto.php script - I use
it a lot. The common.php.inc just stuffs all the variable, POST, GET,
FILE, etc... into the $args array. database.php.inc includes a number of
handy database function, dbConnect() and echoFatalError() among them.
<?php require('../php/common.php.inc'); ?>
<?php require('../php/database.php.inc'); ?>
<?php
$db_id = dbConnect("test");
if ( $args['id'] )
{
$id = $args['id'];
}
if ( $args['thumb'] )
{
$format = "Thumb";
}
else
{
$format = "Photo";
}
if ( $id == "" )
exit();
$sql = "SELECT $format FROM Photos WHERE ID = $id";
$result = @mysql_query( $sql, $db_id );
if ( !$result )
{
echoFatalError( $sql . " failed: " . mysql_error($db_id) );
}
$data = @mysql_result($result, 0, $format);
if ( $type == "" )
{
$type = "image/jpeg";
}
Header("Content-type: $type");
echo $data;
?>