1

In MYSQL database I store many images in a single field by seperating them with commas.

In my android application I have to show only single image or first image at a time.

How to get and store all the images from database in my code which is seperated by comma and display only one at a time??

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Ramz
  • 935
  • 2
  • 12
  • 29
  • you do that in the back end (server) and probably gonna be faster. do you have php? – Tasos Jan 04 '16 at 10:50
  • you can fetch all the images and store it in a string array(If those images has path) and use swiper to change image one after the other give some time interval and pass this string array. Or If you want to display only one image like first or last then set string array first or last string to the image view – Hanuman Jan 04 '16 at 10:57
  • @Tasos Yes I have php. Could you please explain how to do that in php?? – Ramz Jan 04 '16 at 10:59
  • this is a a basic tutorial on how to get data from mysql db using php in various methods -- mysqli method is recommended in the php docs if you have the latest version of mysql db-- http://www.w3schools.com/php/php_mysql_select.asp -- however because you have data separated in comas you going to need another step which is to unseparate and put into array -- check here for that -- http://stackoverflow.com/questions/1125730/how-can-i-split-a-comma-delimited-string-into-an-array-in-php -- after that you send the data back to the App via json e.g (echo json_encode($data,JSON_PRETTY_PRINT);) – Tasos Jan 04 '16 at 11:19

3 Answers3

0

You can get all images with commas. After you can split your string with commas in Array and you add your logic in Java, List of String

rdn87
  • 739
  • 5
  • 18
0

Fetch all the image path from db into an arraylist/array by splitting your comma separated string and then loop through that arraylist/array to show your images one at a time. To create that arraylist create a position variable and update that position variable with the index of comma and then find substring using that index

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
0

You can get individual image URLs by splitting the string with ','

String[] images = imageStringFromDB.split(",");

The images array contains all the image paths. You can load any of the element in ImageView by creating an AsyncTask to download the Bitmap from URL.

Vikram Kumar
  • 300
  • 2
  • 10