Stack Exchange
How Retrieve image from database and display on a UITableView Cell
I have a SQL database (DB-name: testdbb) on a server(localhost) that contain one table. This is the structure:
ID(Integer AutoIncrement)
Name(VARCHAR)
Message(TEXT)
Image(BLOB)

And this is the code for the php script (the name of the file is getJson.php):
<?php
$username = "root";
$database = "testdbb";

mysql_connect (localhost, $username);
@mysql_select_db ($database) or die ("ERROR");
$query = "SELECT *  FROM test";
$result = mysql_query($query) or die (mysql_error());
$num = mysql_numrows($result);
mysql_close();

while ($r = mysql_fetch_assoc($result)){
    $rows[] = $r;
}
echo json_encode ($rows);
?>

Yhe name of the UIViewController is CompteInternet. I define a constant (#define KGetUrl @"http://localhost/getJson.php") and I use it in the implementation of CompteInternet.m.
This is the code in the method of the UITableView: 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSURL *url = [NSURL URLWithString:KGetUrl];
    NSData *data = [NSData dataWithContentsOfURL:url];
}

And I retrive the image like this :
UIImage * image = [UIImage imageWithData:data];

After retrieving the image I want to display it in the tableView
cell.imageView.image = image;

But it doesn't work, so I add a UIImageView and I named it Image1 so I can display the image:
[image1 setImage:image];

But it doesn't work either. I tried another solution using NSDictionary: 
NSDictionary *info = [json objectAtIndex:indexPath.row];
cell.textLabel.text = [info objectForKey:@"Name"];

And it shows me the result with success but it doesn't show me the image and I haven't gotten any errors.

please print "data" in log and see....u get data ??

yes I do it and it show me the data I told I display in TableView the name and I test if my Image is empty and it isn't empty

what u can see in your imageView ?? if u cant see image

I don't see the Image ,I retrive the image but I can not display it :(

set red color of your imageview and see......after retrieving image u can see red color....

yes I do it and it turn to a rectangle red but it doesn't show the image in the sql DB

after adding image in UIImageView......u can see red color ??

no it doesn't turn to red so I assume that I'm not getting the image !!!

but when I use this code
UIImage *img = [UIImage imageNamed:[info objectForKey:@"Image"]];
I have this error
-[NSNull length]: unrecognized selector sent to instance
So I'm not getting the image from the sql data base

and when I display the data by accessing the page http://localhost/getJson.php

I get this entry [{"Id":"2","Name":"Dragon","Message":"Ball z","Image":"(null)"} and I don't khnow why the value of the Image is empty (NULL)
