I'm trying to figure out how to return a blob image that's stored in a table in my mysql database.
here is my code:
<?php
$DBConnect = mysqli_connect("localhost", "root", "newpwd", "portfolio")
Or die("<p>Connection failed dude!</p>");
$SQLString = "SELECT * FROM projects";
$QueryResult = mysqli_query($DBConnect, $SQLString);
echo "<table width='10%' border='1'>";
echo "<tr><th>Project</th><th>Description</th><th>Link</th></tr>";
$Row = mysqli_fetch_row($QueryResult);
do {
//display proj_id, proj_desc
echo "<tr><td>{$Row[0]}<td>{$Row[1]}</td>";
//display proj_img
$id = $_GET['id'];
$query = mysql_query("SELECT port_img FROM projects WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];
header('Content-type: image/jpg');
echo "<td>$Content;</td></tr>";
$Row = mysqli_fetch_row($QueryResult);
} while ($Row);
mysqli_close($DBConnect);
echo "</table>";
?>
Can anyone help me figure this out?
Thanks.
returning blob from mysql database using php
Moderator: General Moderators
-
fairyprincess18
- Forum Newbie
- Posts: 21
- Joined: Sun Dec 07, 2008 8:54 pm
Re: returning blob from mysql database using php
You can't display HTML and an image at the same time. Dedicate a PHP page to creating the image and use an <img> in the HTML page to link to it.
-
fairyprincess18
- Forum Newbie
- Posts: 21
- Joined: Sun Dec 07, 2008 8:54 pm
Re: returning blob from mysql database using php
Here's my call in the HTML file:
echo "<td><img src='fetchImage.php?imgID=1' /></td></tr>";
and here's fetchImage.php:
<?php
$DBConnect = mysqli_connect("localhost", "root", "newpwd", "portfolio")
Or die("<p>Connection failed dude!</p>");
$x = mysql_real_escape_string($_GET['id'], $DBConnect);
$result = mysql_query("SELECT port_img FROM projects WHERE imgID=$x", $DBConnect);
$blobby = mysql_fetch_row($result);
header("Content-type: image/jpeg");
echo $blobby;
exit;
?>
it still doesn't work. can you tell me why?
echo "<td><img src='fetchImage.php?imgID=1' /></td></tr>";
and here's fetchImage.php:
<?php
$DBConnect = mysqli_connect("localhost", "root", "newpwd", "portfolio")
Or die("<p>Connection failed dude!</p>");
$x = mysql_real_escape_string($_GET['id'], $DBConnect);
$result = mysql_query("SELECT port_img FROM projects WHERE imgID=$x", $DBConnect);
$blobby = mysql_fetch_row($result);
header("Content-type: image/jpeg");
echo $blobby;
exit;
?>
it still doesn't work. can you tell me why?
Re: returning blob from mysql database using php
1. You can't mix-and-match MySQL and MySQLi functions.
2. mysql_fetch_row returns a row, not the contents of a single field. Read the manual page.
2. mysql_fetch_row returns a row, not the contents of a single field. Read the manual page.
-
fairyprincess18
- Forum Newbie
- Posts: 21
- Joined: Sun Dec 07, 2008 8:54 pm
Re: returning blob from mysql database using php
i tried this:
it still doesn't work though
Code: Select all
<?php
$DBConnect = mysqli_connect("localhost", "root", "newpwd", "portfolio")
Or die("<p>Connection failed dude!</p>");
$result = mysqli_query("SELECT * FROM projects");
$Row = mysqli_fetch_row($result);
header("Content-type: image/jpeg");
echo "{$Row[2]}";
exit;
?>
Re: returning blob from mysql database using php
Read the manual pages. Here is the one for mysqli_query and ... oh wait, there aren't any functions called "mysqli_fetch_row".