1

Is there any way to download a certain amount of rows from JSON? I have a MySQL database converted to JSON.

The JSON data is large and more than 1000 rows. obviously, i cannot download and parse all of them into my SQLite database in android at once.

I need to download a few rows and load more on Recyclerview scrolling. How can i tell volley to load a few of JSON rows not all of them?

Ramesh sambu
  • 3,577
  • 2
  • 24
  • 39
Swrena
  • 310
  • 3
  • 12

2 Answers2

1

Use LIMIT while detching the Data using SQL Query for fetching Data from MYSql Server.

SELECT * FROM your_table WHERE your_condition LIMIT number_of_rows;

This will Return only Return number_of_rows rows while fetching Data.

SELECT * FROM your_table WHERE your_condition LIMIT starting_row,ending_row;

This will Return only Return n number of rows starting from starting_row to ending_rowwhile fetching Data.

Tomin B Azhakathu
  • 2,656
  • 1
  • 19
  • 28
  • It fetches the limited data from the first row. If i recall it will download the same rows. How can i tell it to fetch the next rows? – Swrena Dec 22 '17 at 15:16
  • @Sorena You Can Refer https://stackoverflow.com/questions/1492297/how-to-get-all-rows-starting-from-row-x-in-mysql for Achiving the Function You Had Requested – Tomin B Azhakathu Dec 22 '17 at 15:25
  • Pass The Limit and Offset as Parameters . So You Can Easily achieve The Function – Tomin B Azhakathu Dec 22 '17 at 15:26
  • Sorry i don't get it. If i set offset and limit it'll fetch the limited data started from offset. offset is the same on every call. – Swrena Dec 22 '17 at 16:40
  • Pass Offset and Limit as GET Parameter... On Everytime That will Change and You will Get updated Value... If This Seems Difficult For U Try Using Pagination. For Me I Find This more Easier. Everyones Prespective are Different. So Try Different Methods – Tomin B Azhakathu Dec 22 '17 at 16:43
  • No i don't think it's difficult. I just don't know what is GET parameter. could you give an example? – Swrena Dec 22 '17 at 16:52
  • Just Pass Parameter as GET or POST Method while Calling The URL using Volley. Google it.. – Tomin B Azhakathu Dec 22 '17 at 16:59
  • This is how i fetch it: `jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, HTTP_SERVER_URL, new Response.Listener() {` .But still the same. Fetches the same rows. – Swrena Dec 22 '17 at 18:52
  • @Sorena How Did u pass your starting and Ending row numbers – Tomin B Azhakathu Dec 23 '17 at 04:26
  • Thanks. i made it.. i just had a problem with StringRequest – Swrena Dec 28 '17 at 15:49
  • Whats the problem – Tomin B Azhakathu Dec 28 '17 at 15:50
  • nothing. i fixed it thanks. just converting `JSON` as String to a `JsonArray` caused me problems. now i can change offset everytime. – Swrena Dec 28 '17 at 15:52
0

With pagination you can achieve this. Basically at server side you create API which will return some set of data like 50 set or 100 or may be more than that, So whenever you will load that set in your ListView or RecyclerView and on click of Load More or scroll end you call same API again to fetch other set of data and load in app.

If you are using Volley then use same logic to achieve it

Nikhil Lotke
  • 605
  • 7
  • 15
  • Right i limited the `PHP` to fetch limited data. How can i make that API which returns the next rows on load more. Not the same rows again. – Swrena Dec 22 '17 at 15:17
  • Well lets consider 50 set here and at server side you are having approx 40k rows where all are having unique id's lets consider as rowId. Now for the 1st time API call you pass 0 as rowId so that API will understand this is 1st call and will return first 50 set of data along with latest rowId. Store this rowId and in next API call pass this latest one, now server will consider this rowId and search in database, once matched then API will return you the next 50 set. Likewise you proceed with API calls on load more event. – Nikhil Lotke Dec 26 '17 at 08:53