hi,can anyone plz help me..the coding wuz ok,it generate the image from in my directories except it shows a blank image...i don't know wats the prob,plz help me...
here is the coding...

<?php
// connect to mysql server
$link = mysql_connect('localhost', 'root', 'abc123');
if (!$link) {
    die('Not connected : ' . mysql_error());
}
// connect to database server
$db_selected = mysql_select_db('test', $link);

if (!$db_selected) {
    die ('Database error : ' . mysql_error());
}

        $sql = "select img_name from templates where img_id=1";

        // the result of the query
        $result = mysql_query($sql) or die("Invalid query: "  .mysql_error());

        // Header for the image

        while ($pic = mysql_fetch_array($result)){
        //echo $pic[img_name];
        //header("Content-type: image/jpeg"); 
        echo "<img src='picture/".$pic[img_name]."' width='300'               height='300' />" ;

        }

?>

Recommended Answers

All 3 Replies

This should work:

<?php
// connect to mysql server
$link = mysql_connect('localhost', 'root', 'abc123') or die('Not connected : ' . mysql_error());

// connect to database
$db_selected = mysql_select_db('test', $link) or die ('Database error : ' . mysql_error());

// create the query
$sql = "select img_name from templates where img_id=1";

// the result of the query
$result = mysql_query($sql) or die("Invalid query: " .mysql_error());

// there should only be 1 result (if img_id = the primary index)
$pic = mysql_fetch_array($result);

// show the image
echo "<img src='picture/".$pic['img_name']."' width='300' height='300'/>";
?>

I presume there is only 1 image with img_id 1. If so, you don't need a while loop on the results. Just get the result and display it. And don't forget to place either ' or " around the field name in the resulting array (see line 18)

reli thanks 4 helping...bt stil im getting blank image aftr usin it,izit anytn wrong wit my table..?
here i state my sql query,
SELECT *
FROM `templates`
LIMIT 0 , 30

SELECT COUNT( * ) AS `Rows` , `img_id`
FROM `templates`
GROUP BY `img_id`
ORDER BY `img_id`
LIMIT 0 , 30

SELECT COUNT( * ) AS `Rows` , `img_name`
FROM `templates`
GROUP BY `img_name`
ORDER BY `img_name`
LIMIT 0 , 30

i've created only 2 rows[img_id | img_name]
it shld show template_1.jpg whic id=1
i saves the template folder in same same directories as the code..
duno wat is the prob,i'l b glad if u cn help me wit that...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.