PDA

View Full Version : HOw o return a huge amount of data from php to javascript?



defmer
12-29-2008, 02:51 AM
I have a very very limited knowledge about Ajax, JS and PHP, so I could really use help is trying to finish this. OK that said,

1) what I am trying to do is send request to a php page using XMLHttpRequest in jS to get records from a mysql database.

2) The request to the database returns 4 columns of data with over 2000 rows.

3) I managed to use html_Table.php to print out the table from php itself. But I actually need to get the data back to client side (JS) for formating and other formating stuff. I tried everything to get the data to the client side but nothing seems to work.

so how do I pass this table to the client side? if there is no way to do that then , how do I pass/return and access the data which is represent as 4 Row X 2000 COL.

I did try to return an array but was only able to successfully return one row with every request to php. I had formated each element of the row as "'john, ohio, 5555555, 12345". which is not helpful.

I really appreciate any help with this problem. thank you.

P.S. I am attaching my files along with this post. I had to change the extensions so that I could attach them.

djr33
12-29-2008, 03:05 AM
That is very likely an inefficient way to do it.
You should process the data first with PHP, which will be must faster, less data to send and less work for the user's computer (that much data could give big problems to an older computer, especially if the Javascript isn't running efficiently).
But if you must use it in Javascript for some reason (maybe if you're working with the data live, in order to manage it), then you should do so by having php write an array, as you said. There's no easier way to do it, but there might be an easier way to access the array. Rather than just "1,2,3,4" maybe you should put it in labeled parts of the array, or organize it so it's easier to search.
However, this really is the point of a database and what people usually do is to search the database itself with PHP to return what you need, THEN and only then deal with it using Javascript. Remember, also, that you could run the request multiple times if you need more than one chunk of data, but that it will just slow things down to get it all.

diltony
12-31-2008, 12:29 AM
My ajax library have some multistep techniques that can help you with loading them in a chunk at a time, but this is generally an inefficient method, i think it is better to allow user to specify the aspect they want and edit that content. Even ajax is not meant to load the entire site....it has a limit. Even if you load it in with ajax, u cant submit all that info in one step with ajax, i will like to suggest an <iframe> in this situation, see how you can manage it.