Mssql image not displaying properly

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
MikeMessiah
Forum Newbie
Posts: 1
Joined: Wed Mar 05, 2008 2:57 pm

Mssql image not displaying properly

Post by MikeMessiah »

OK, no one answered on another forum so I will try elaborate some more and maybe someone can shed some light on this. Basically I need to pull out related images and display them in my main page. The problem is that I either get no image coming back ( just the image placeholder ), or I can get a bunch of hex garbage to come back. Here is the mini.php page i use :

<?php #mini.php
// Used to locate record based on ID number
// Should pass image back and display
require_once( "./common_db.php" );

if ( ! $link_id = db_connect($default_dbname) ) {
die( "connection to db failed" );
}

$id = $_GET['id'];
$q = "select Photo1 from $user_tablename where ID = $id";

if ( ! $image_result = mssql_query($q,$link_id) ) {
die( "error with query: $q" );
}

if ( mssql_num_rows( $image_result ) < 1 ) {
die( "no results found" );
}

$image = mssql_fetch_assoc( $image_result );

//echo $image;

header("content-type image/jpeg");
echo $image['Photo1'];

//Print $image;
//echo($image);

?>

Here is the part of code that calls mini.php


while($query_data = mssql_fetch_array($result))
{
$ID = $query_data["ID"];
$StreetAddress = $query_data["Street_Address"];
$Price = $query_data["Price"];
$Zone1 = $query_data["Zone1"];
//$Photo1 = $query_data["Photo1"];
//$Photo2 = $query_data["Photo2"];
//$Photo3 = $query_data["Photo3"];
//$Photo4 = $query_data["Photo4"];

echo "<TR>\n";
echo "<TD WIDTH=\"111\" ALIGN=\"LEFT\"><font size=\"2\">$ID</font></TD>\n";
echo "<TD WIDTH=\"128\" ALIGN=\"LEFT\"><font size=\"2\">$StreetAddress</font></TD>\n";
echo "<TD WIDTH=\"121\" ALIGN=\"LEFT\"><font size=\"2\">$Price</font></TD>\n";
echo "<TD WIDTH=\"67\" ALIGN=\"LEFT\"><font size=\"2\">$Zone1</font></TD>\n";
echo "<TD WIDTH=\"46\" ALIGN=\"LEFT\"><img src='mini.php?id=$ID'></TD>\n"; // Calls mini.php which should locate the image by ID number and pass it back with the correc header // echo "<TD WIDTH=\"46\" ALIGN=\"LEFT\"><img src='D:\Mike Misc\Graphics\Wallpapers\1.jpg'></TD>\n";
// echo "<TD WIDTH=\"46\" ALIGN=\"LEFT\"><img src=\"$Photo1\"/></TD>\n";
// echo "<TD WIDTH=\"48\" ALIGN=\"LEFT\"><font size=\"2\">$Photo2</font></TD>\n";
// echo "<TD WIDTH=\"93\" ALIGN=\"LEFT\"><font size=\"2\">$Photo3</font></TD>\n";
// echo "<TD WIDTH=\"243\" ALIGN=\"LEFT\"><font size=\"2\">$Photo4</font></TD>\n";

echo "</TR>\n";
}


Any ideas why it doesnt work. I am lost.
Post Reply