
October 28th, 2009, 02:32 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 1
Time spent in forums: 15 m 19 sec
Reputation Power: 0
|
|
|
php5 - Display a database thumbnail link
Hi everybody.
I have a website people can use to find a car by using scrolldown menus and selecting certain item for example mark, colour and age. to do this I use a MYSQL database and php5. To update the database I use phpmyadmin.
I have the following problem. When people make a selection the result may be multiple cars. On the result page they see a column which displays the results by: Mark of the car and a photo of the car. The save processing time I only display a thumbnail. What I would like to do is the display these thumbnails as links to the original size photo. So when someone clicks on the thumbnail displayed, the original photo pops up. I found the "Lightbox2" application on the internet and was wondering, does anybody knows how to implement this lightbox effect into my script?
my script (simplified version):
Code:
<?php
error_reporting ( E_ALL );
ini_set ( 'display_errors', 1 );
?>
<?php
include inlog.php
?>
<?php
$merken = array("audi","bmw","opel");
$kleuren = array("blauw","groen","rood",);
if($_SERVER['REQUEST_METHOD'] == 'POST' ) {
$where = array();
if (isset($_POST["merk"]) && in_array($_POST["merk"],$merken)) {
$where[] = "MERK='".$_POST["merk"]."'";
}
if (isset($_POST["kleur"]) && in_array($_POST["kleur"],$kleuren)) {
$where[] = "KLEUR='".$_POST["kleur"]."'";
}
if (isset($_POST["bouwjaar"]) && preg_match("/^(19|20)\d\d$/i", $_POST["bouwjaar"])) {
$where[] = "BOUWJAAR='".$_POST["bouwjaar"]."'";
}
if (count($where)==0) {
echo "Geen zoektermen bekend. Opdracht geannuleerd.";
} else {
$query = "select ID, MERK, KLEUR, BOUWJAAR from catalog_tabel WHERE ".implode(" AND ",$where);
if ($result = mysql_query($query)) {
if (mysql_num_rows($result)<>0) {
while ( $row = mysql_fetch_assoc ( $result ) ) {
echo $row["MERK"]." - ".$row["KLEUR"]." - ".$row["BOUWJAAR"]."<br />";
$beschrijvingquery = "select BESCHRIJVING from beschrijving where Catalog_ID=".$row["ID"];
if ($beschrijvingresult = mysql_query($beschrijvingquery)) {
if (mysql_num_rows($beschrijvingresult)<>0) {
while ( $beschrijvingrow = mysql_fetch_assoc ( $beschrijvingresult ) ) {
echo $beschrijvingrow["BESCHRIJVING"]."<br />";
}
} else {
echo "geen beschrijving<br />";
}
}
$fotoquery = "select FOTO from foto where Catalog_ID=".$row["ID"];
if ($fotoresult = mysql_query($fotoquery)) {
if (mysql_num_rows($fotoresult)<>0) {
while ( $fotorow = mysql_fetch_assoc ( $fotoresult ) ) {
echo "<img src='".$fotorow["FOTO"]."' alt='".$row["MERK"]." - ".$row["KLEUR"]." - ".$row["BOUWJAAR"]."' /><br />";
}
} else {
echo "<img src='geenfoto.jpg' alt='geen foto' /><br />";
}
}
}
} else {
echo "Geen auto's gevonden die voldoen aan uw zoekopdracht.";
}
}
}
}
?>
<hr />
<form method="post" action="results.php">
<select name="merk">
<option selected="selected">Merk</option>
<option><?php echo implode("</option><option>",$merken); ?></option>
</select>
<select name="kleur">
<option selected="selected">Kleur</option>
<option><?php echo implode("</option><option>",$kleuren); ?></option>
</select>
<select name="bouwjaar">
<option selected="selected">Bouwjaar</option>
<option>1990</option>
<option>1991</option>
<option>1992</option>
</select>
<input type="submit" value="zoeken" />
</form>
I also found the following code on the internet thats should display thumbnails as links but I also do not know how to implement this code into my own script to make it work.
Code:
query.php
<?php
session_start();
?>
<html>
<?php
// connect to database
// the database has fields: thumbs, reference, and description
$db = mysql_connect("host","name","password");
mysql_select_db("database",$db) or die ('Unable to connect to database');
$q="SELECT * FROM table";
$result = mysql_query( $q, $db )
or die(" - Failed More Information:<br><pre>$q</pre><br>Error: " . mysql_error());
//if result carry on
$num_rows = mysql_num_rows($result);
if ($myrow = mysql_fetch_array($result)) {
//specify thumbnail folder
$tn='<img src=http://your_web_site/thumbs/';
// specify target for link
// in this case it's to retrieve more info based on the thumbnail
$web='http://your_web_site/detail/index.php?name=';
echo "<br>Listed below<BR><br>";
echo "<table border=1>\n";
echo "<tr><td><b>Reference:</b></td><td>Text:</td><td>Thumb:</td></tr>\n";
do {
// 3 columns in this example
printf("<tr><td>%s</td><td>%s</td><td><a href=$web%s>$tn%s.jpg></a></td></tr>\n",
//display reference, description and thumb database info in this example
// the last 2 combine into a link with a reference to carry
// just one column, thumb alone, would be
// printf("<tr><td><a href=$web%s>$tn%s.jpg></a></td></tr>\n",
// $myrow["reference"], $myrow["thumb"]);
$myrow["reference"], $myrow["description"],$myrow["reference"], $myrow["thumb"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "<font face=verdana,arial,helvetica size=2 color=blue>Sorry -- the records appear to be unavailable</font>:<br>Has there been a typo? Try again?";
}
mysql_free_result($result);
mysql_close($db);
?></html>
________________________________________
/detail/index.php
<?PHP
session_start();
?>
<html>
<?php
$ref="$name";
if (empty($ref)) {
echo "Oooops, lost the reference";
// and exit
exit;
}
//do a database query on that reference
$query = "SELECT * FROM db_table WHERE reference='$ref'";
?>
</html>
I hope you can help me
|