Retreiving Images from Database
Posted: Wed Oct 07, 2009 12:50 pm
Hey all, I'm new to php and have a question. Any help would be appreciated. I am able to get images into my database using the help from http://www.phpbuilder.com/columns/flori ... hp3?page=1 but I'm having trouble implementing the retrieval of the image in my script below.
<html>
<head>
<title>Custom Foam Interior Templates</title>
</head>
<body>
<?php
$myvar = $_POST['formVar'];
$myvar2 = $_POST['formVar2'];
$myvar3 = $_POST['formVar3'];
$con = mysql_connect('host','username','password');
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("caseclu_foaminterior", $con);
if(isset($_POST["q"]))
$selection = $_POST["q"];
else
$selection = null;
switch ($selection)
{
case "all":
$query = "SELECT * FROM interiors";
break;
case "id":
$query = "SELECT * FROM interiors WHERE id like '%$myvar3%'";
break;
case "custom":
$query = $_POST["cq"];
break;
case "category":
$query = "SELECT * FROM interiors WHERE category='$myvar2'";
break;
case "search":
$query = "SELECT * FROM interiors WHERE description like '%$myvar%'";
break;
default:
echo 'Nothing to do here';
}
$q = mysql_query($query)
or die("This is not a valid query: " . $query);
$fieldCount = mysql_num_fields($q);
echo "You selected the query <i>$query</i>.<br />
Here are your results: <br /><br />
<table border='1'>
<tr>";
// print table headers
for($i=0; $i<$fieldCount; $i++)
{
$field = mysql_fetch_field($q);
echo "<th>{$field->name}</th>";
}
echo "</tr>\n";
// Print table rows
while($record = mysql_fetch_row($q))
{
echo "<tr>";
foreach($record as $cell)
echo "<td>$cell</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
Does anyone know how to display the image field with the actual images rather than all the random characters. I am able to follow his tutorial http://www.phpbuilder.com/columns/flori ... hp3?page=2 on the next page to view the image, but no luck implementing it into my pre-exsisting queries. Any help is appreciated!
<html>
<head>
<title>Custom Foam Interior Templates</title>
</head>
<body>
<?php
$myvar = $_POST['formVar'];
$myvar2 = $_POST['formVar2'];
$myvar3 = $_POST['formVar3'];
$con = mysql_connect('host','username','password');
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("caseclu_foaminterior", $con);
if(isset($_POST["q"]))
$selection = $_POST["q"];
else
$selection = null;
switch ($selection)
{
case "all":
$query = "SELECT * FROM interiors";
break;
case "id":
$query = "SELECT * FROM interiors WHERE id like '%$myvar3%'";
break;
case "custom":
$query = $_POST["cq"];
break;
case "category":
$query = "SELECT * FROM interiors WHERE category='$myvar2'";
break;
case "search":
$query = "SELECT * FROM interiors WHERE description like '%$myvar%'";
break;
default:
echo 'Nothing to do here';
}
$q = mysql_query($query)
or die("This is not a valid query: " . $query);
$fieldCount = mysql_num_fields($q);
echo "You selected the query <i>$query</i>.<br />
Here are your results: <br /><br />
<table border='1'>
<tr>";
// print table headers
for($i=0; $i<$fieldCount; $i++)
{
$field = mysql_fetch_field($q);
echo "<th>{$field->name}</th>";
}
echo "</tr>\n";
// Print table rows
while($record = mysql_fetch_row($q))
{
echo "<tr>";
foreach($record as $cell)
echo "<td>$cell</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
Does anyone know how to display the image field with the actual images rather than all the random characters. I am able to follow his tutorial http://www.phpbuilder.com/columns/flori ... hp3?page=2 on the next page to view the image, but no luck implementing it into my pre-exsisting queries. Any help is appreciated!