I have a script that grabs input from a form and queries a database based on the input into the form. I have added a field for photo link. The data in the database reflects the image location (eg. Images\picture.jpg)
Here is a little code for ya,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #000000;
background-image: url(Images/MainFrameBG.gif);
}
.style1 {color: #FFFFFF}
body,td,th {
color: #FFFFFF;
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
text-align: center;
}
--></style></head>
<body>
<div align="left"></div>
<?php
//------------------------------------------------------------------------------------------
// INITIALIZING VARIABLES
$hostname = "localhost";
$username = "root";
$password = "mastercut";
$dbname = "mastercut";
$usertable = "tblendmills";
//-------------------------------------------------------------------------------------------
// DEBUGGING TO SEE IF VARIABLE ARE PASSED, .. VARIBLES POSTED FROM FORM
?><h1>
<?php
$unitstitle = $units;
if(empty($units)){
$unitstitle = 'Fractional and Metric';
}
$typestitle = $type;
print "$unitstitle $typestitle";
?>
</h1><?php
//-----------------------------------------------------------------------------------------
// CONNECTION TO DATABASE
mysql_connect($hostname,$username,$password) or die("Unable to connect to database");
mysql_select_db($dbname) or die("Unable to select database");
// REASSIGNING EMPTY VARIABLES TO WILDCARDS
//-------------------------------------------------------------------------------------------
if(empty($units)){
$units = '%';
}
//-------------------------------------------------------------------------------------------
if(empty($partnum)){
$partnum = '%';
}
//-------------------------------------------------------------------------------------------
if(empty($diameter)){
$diameter = '%';
}
//-------------------------------------------------------------------------------------------
if(empty($LOC)){
$LOC = '%';
}
//------------------------------------------------------------------------------------------
if(empty($shank)){
$shank = '%';
}
//-----------------------------------------------------------------------------------------
if(empty($oal)){
$oal = '%';
}
//-----------------------------------------------------------------------------------------
// NO IF STATEMENT NEEDED FOR LAST TWO FORM VARIABLES THEY ARE ASSIGNED BY THE DROP DOWN
//-----------------------------------------------------------------------------------------
//QUERYING DATABASE FOR RECORDS
$result = mysql_query("SELECT * FROM tblendmills WHERE
tblendmills.type LIKE '$type' AND
tblendmills.units LIKE '$units' AND
tblendmills.partnum LIKE '$partnum' AND
tblendmills.diameter LIKE '$diameter' AND
tblendmills.LOC LIKE '$LOC' AND
tblendmills.shank LIKE '$shank' AND
tblendmills.oal LIKE '$oal' AND
tblendmills.flutes LIKE '$flutes' AND
tblendmills.coating LIKE '$coating' AND
tblendmills.endtype LIKE '$endtype'");
$number = mysql_num_rows($result);
// SETTING UP TABLE HEADS
?>
<table border="1">
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th colspan="4" scope="col" bgcolor="#0066FF">Dimensions</th>
<th> </th>
<th> </th>
<th> </th>
<tr bgcolor="#0066FF">
<th>Part Number</th>
<th>Endmill Type</th>
<th>Flutes</th>
<th>Endtype</th>
<th>Cutting Edge Diameter</th>
<th>Cutting Edge Length</th>
<th>Shank Diameter</th>
<th>Overall Length</th>
<th>Coating</th>
<th>List Price</th>
<th>Photo</th>
<?php
$i = 0;
if($number == 0){
print "<center>No Parts Found</center>";
}
elseif ($number > 0){
print "<center>There Were $number Endmills Found Matching Your Query: </center><BR>";
while ($i < $number):
?>
<tr>
<td>
<?php
$partnum = mysql_result($result,$i,"partnum");
print "$partnum";
?></td>
<td>
<?php
$type = mysql_result($result,$i,"type");
print "$type";
?></td>
<td>
<?php
$flutes = mysql_result($result,$i,"flutes");
print "$flutes";
?></td>
<td>
<?php
$endtype = mysql_result($result,$i,"endtype");
print "$endtype";
?></td>
<td>
<?php
$diameter = mysql_result($result,$i,"Diameter");
print "$diameter";
?></td>
<td>
<?php
$LOC = mysql_result($result,$i,"LOC");
print "$LOC";
?></td>
<td>
<?php
$shank = mysql_result($result,$i,"Shank");
print "$shank";
?></td>
<td>
<?php
$oal = mysql_result($result,$i,"oal");
print "$oal";
?></td>
<?php
//------------------------------------------------------------------------------------
$coating = mysql_result($result,$i,"coating");
switch ($coating)
{
case "TiN":?>
<td bgcolor="#FFCC33"><?php
break;
case "TiCN":?>
<td bgcolor="#999999"><?php
break;
case "TiALN":?>
<td bgcolor="#660033"><?php
break;
default:?>
<td bgcolor="#000000"><?php
break;
}
print "$coating";?>
</span></td>
<td><span class="style3">
<?php
$list = mysql_result($result,$i,"list");
print "$ $list";
?></span></td>
<td><span class="style3">
<?php
$photo = mysql_result($result,$i,"photo");
?>
<a href="viewphoto.php" class="style2"><em><img src="Images/camara.gif"></em></a>
</span></td>
<?php
$i++;
endwhile;
}
?>
</body>
</html>
Here is the contents of viewphoto.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<em><img src="<?php '$photo'; ?>" width="244" height="181" align="top"></em>
</body>
</html>
I know that nothing is being passed, that is the first problem. I have Globals turned on in PHP
Next problem, even if I do get it to display an image, wont it only display the image of the last record in the query. $photo is updated during the while statement.
I can have the output include the direct link, but I kinda want the icon,
maybe something like:
<?php
$photo = mysql_result($result,$i,"photo");
?>
<a href="<em><img src="<?php $photo?>"></em>" class="style2"><em><img src="Images/camara.gif"></em></a>
</span></td>
<?php
Thank you beforehand for any insight/info
Shanis