| Page 1 of 1 | [ 9 posts ] |
|
I'm really new to all of this...so I apologize for stupid questions in advance.
What I'm able to do: I have a mysql database and a php file that has a function that generates a results.json file. Anotherwords I can query the database and output results. I don't know how to send the results to a datatable in yui 3. I tried looking at the datasource help and the base datatable examples but so far have not had any luck in understanding this. I'm really new to this so if someone could provide some guidance I'd really appreciate it. Thanks! |
|
I have now gone a bit farther. I'm using:
var myDataSource = new Y.DataSource.IO({source:"myScript.php"}), myCallback = { success: function(e){ alert(e.response); }, failure: function(e){ alert("Could not retrieve data: " + e.error.message); } }; I'm getting a failure however. In order for DataSource.IO to get data from the php file I just have to echo that data right? So the PHP file will get a query from mysql and then echo it. |
|
Hi Gennady,
Have you looked over the YUI 3 user guide, specifically the YQL example at http://yuiblog.com/sandbox/yui/3.3.0pr3/examples/datatable/datatable_dsget.html ? This example uses a URL (which could be replaced with your php url) and a JSON schema response object (which could be replaced with your response results object and column names). If you need more help, please ask Todd |
|
Yes your php server DEFINITELY has to "echo" something. I do a lot of YUI 2 datatable work but haven't migrated my work over to YUI 3 yet. I haven't seen many postings on this forum regarding YUI 3 DT with remote calls other than YQL. I suggest you search the forum including keywords for 'YUI 3', 'DataTable', 'JSON' to see how others are doing it.
Having said all that, I just put together a quick demo of a YUI 3 DataTable and included the PHP source code for a back-end data server. A public link is available at http://blunderalong.com/yui/dtb/dt_json_io.html. This is pretty basic, but should show the fundamentals of using a DataSource.IO via JSON and what is required on the server-side. Another good source for writing PHP back-ends for YUI 2.x (but same concept) is available on http://www.satyam.com.ar/yui/#phpjson. Good luck, Todd Last edited by stlsmiths on Thu Mar 01, 2012 1:51 pm, edited 1 time in total. |
|
Todd,
I get an error that the function db_lookup is undefined. Also when I do "require_once 'JSON.php';" it pastes the contents of JSON.php in the browser when I run it. Is this normal? Thanks, -Gennady |
|
Ok...including the json.php file is fixed. Its no longer an issue.
My php file generates the following: Array{"replyCode":"k","replyText":"j","Results":{"pkService":"1","FirstName":"Jack","Middle":"S","LastName":"Jones"}} I'm using firebug to read this. I'm using different code though: $query = "SELECT * FROM myTbl limit 20"; $result = mysql_query($query) or trigger_error(mysql_error().$query); $row = mysql_fetch_assoc($result); $returnValue = array( 'replyCode' => 'k', 'replyText' => 'j', 'Results' => $row ); header("Content-Type: application/json"); header("Cache-Control: no-cache"); echo $returnValue; echo json_encode($returnValue); When I execute your example using the above code, I get an empty table... Any ideas appreciated. Thanks! |
|
Hi Gennady,
I can tell by some of your questions that you may be a little confused about using PHP. The example link I provided earlier was meant to show my example implementation. You appear to have understood that "db_lookup" is a library function I wrote that simply returns an associative array from MySQL. Sorry, I should have been more clear about that. From the server snippet you provided it looks like you may have an extraneous "echo $returnValue" statement which will mess things up. You only need to have the "echo json_encode($returnValue)" statement. Also, from the example of the output you show it looks like you are only returning a single row with mysql_fetch_assoc, but the 'Results' object of the JSON that is returned is expected to be an array. So I recommend your server call be replaced with the following Code: while ($record = mysql_fetch_assoc ($result)){ $row[] = $record; } where the $row[] assignment appends to the $row array. I recommend again that you review some of Satyam's examples for writing YUI 2 DataTable with php servers, they are very helpful. 1. Essential reading http://www.satyam.com.ar/yui/ 2. Also his YUILibrary articles http://yuiblog.com/blog/2008/10/15/datatable-260-part-one/ 3. and http://yuiblog.com/blog/2008/10/27/datatable-260-part-two/ You haven't shown any of your YUI3 DataTable code so I can't really tell if there are issues there. Once you get your php server worked out if you have problems you may want to use a pastie service to post your code and we can review it. Regards, Todd |
|
Thanks a bunch, really helped me out!
|
|
It worked Todd. My table now has data from the database! Thank you VERY much!
|
| Page 1 of 1 | [ 9 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group