AP81 Posted April 2, 2008 Share Posted April 2, 2008 I know that Ajax isn't really good for large amounts of data, but I often use Ajax to populate tables that may have some 20 to 30 rows. I do something like this: for ($i=0; $i<$this->GetRowCount(); $i++) { $line = $this->GetRow(); if ($i==0) $client_log .= $line["ID"]; else $client_log .= "*^*" . $line["ID"]; $client_log .= "*|*" . $line["DUE_DATE"]; $client_log .= "*|*" . $line["CLIENT_CODE"]; $client_log .= "*|*" . $line["DEAL_TYPE"]; $client_log .= "*|*" . $line["PURCH_RENT"]; $client_log .= "*|*" . $line["CHANGED_DUE_DATE"]; $client_log .= "*|*" . $line["CHANGED_PROCESSED_DATE"]; $client_log .= "*|*" . $line["CHANGED_RECURRING_REVENUE"]; $client_log .= "*|*" . $line["REVENUE_DUE_DATE"]; $client_log .= "*|*" . $line["REVENUE_PROCESSED_DATE"]; $client_log .= "*|*" . $line["REVENUE"]; $client_log .= "*|*" . $line["COMMENTS"]; } echo $client_log; [code] All this does is split up database rows such that fields are separated by '*|*' and rows are separated by '*^*' . I then use the split function to split on *^* to break the data up into rows, then use the split function again on *|* to break up the fields. So my question is, is there a more efficient way to do this? [/code] Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 2, 2008 Share Posted April 2, 2008 Yes, transfer the data as JSON. PHP5+ has functions to output a php array as JSON. So your PHP code would just be: $data = array(); for ($i=0; $i<$this->GetRowCount(); $i++){ $data[] $this->GetRow(); } echo json_encode($data); As far as how to receive it, that will depend on how you are doing your AJAX calls. Most libraries (dojo, jquery, etc) have functions for JSON data being returned. If you are doing the calls the old fashion way, you can just use eval to store it into a variable: var rval; //Data returned by ajax call eval('var data = '+rval+';'); //Now you have a JavaScript object called data to work with Quote Link to comment Share on other sites More sharing options...
AP81 Posted April 2, 2008 Author Share Posted April 2, 2008 sweet. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.