-2

I want to display data in grid view from mysql database using json parser. I can display static image and text but I don't know how to display from database . I have googled but not getting any example.

maulik
  • 1
  • 1

2 Answers2

0

query the database, save in a list then give that list to your adapter. Finally, give the adapter to the gridview.

Zun
  • 1,553
  • 3
  • 15
  • 26
0

First of all; Where is your database ? Which one do you use sqlite or mysql etc. ? I will answer them for you have a mysql database.

CREATE TABLE 'test'.'pic' (
     ...
    'img' LONGBLOB NOT NULL,
  PRIMARY KEY ('idpic')
)

You can create image column table with above code. After create the table and add image to this table(you can add with phpmyadmin) or

INSERT INTO xx_BLOB(ID,IMAGE) 
VALUES(1,LOAD_FILE('E:/Images/yourimage.png'));

you can use above query to add image

You should take image from database with base64_encode you can write a php file to retrive image from database.Below php code help for this.

<?php

  mysql_connect("localhost","root","password");
  mysql_select_db("yourdb");
  $sql=mysql_query("select image from yourtable");

  $i=0;

  while($row=mysql_fetch_assoc($sql))
  {     
//Where Image Exists.First taking path from database and then image from folder against that  path and then //converting it ino base64 and then Json
   $output[$i]['image']= base64_encode(file_get_contents("http://your ip address/ess/uploads/default/products/".$row['image']));
  $i++;
}
print(json_encode($output));

mysql_close();
?>

This php code return your image with base64_encode format than you can parse with volley libray in your android code. I hope this answer may help you.

slymnozdmrc
  • 390
  • 2
  • 8
  • 20