Installation problem with datatables server side processing and wordpress 3.0
Installation problem with datatables server side processing and wordpress 3.0
Hello,
I have a problem to install datatables on my Wordpress site. PHP and jquery are complete new to me.
I am using Wordpress 3.0 and the Thesis theme, Thesis supports jquery. When I set up a new static page on wordpress there is a box to enable jquery for the page. Wordpress opens jquery hosted at google. This works, at least I see the connection in the sourcecode of the page.
Wordpress is installed via xampp at localhost, so I cannot give you a link to the site.
Datatables should open data from a mysql database on a diffrent server, and show this data like on this page:
http://www.datatables.net/examples/data_sources/server_side.html
What I have done by now:
- Downloaded datatables, and saved it to the root directory of my site: (http://loalhost/wordpress/dataTables-1.6 2)
- Edited the file (http://localhost/wordpress/dataTables-1.6 2/examples/examples_support/server_processing.php)
In this file I have added the "Database connection information" (user, password, db, server) and removed the line below this information according to the instructions in the file. I have tested the connection to the database, so I am 100% sure that this works.
- Saved the server_processing.php file.
- Set up a new static page at Wordpress, enabled jquery support and added the initialisation code:
(There is a special box called "add your own javascript", there is the initialisation code.)
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php"
} );
} );[/code]
Please, can you help me, where is the problem?
Thank you very much.
dingo
I have a problem to install datatables on my Wordpress site. PHP and jquery are complete new to me.
I am using Wordpress 3.0 and the Thesis theme, Thesis supports jquery. When I set up a new static page on wordpress there is a box to enable jquery for the page. Wordpress opens jquery hosted at google. This works, at least I see the connection in the sourcecode of the page.
Wordpress is installed via xampp at localhost, so I cannot give you a link to the site.
Datatables should open data from a mysql database on a diffrent server, and show this data like on this page:
http://www.datatables.net/examples/data_sources/server_side.html
What I have done by now:
- Downloaded datatables, and saved it to the root directory of my site: (http://loalhost/wordpress/dataTables-1.6 2)
- Edited the file (http://localhost/wordpress/dataTables-1.6 2/examples/examples_support/server_processing.php)
In this file I have added the "Database connection information" (user, password, db, server) and removed the line below this information according to the instructions in the file. I have tested the connection to the database, so I am 100% sure that this works.
- Saved the server_processing.php file.
- Set up a new static page at Wordpress, enabled jquery support and added the initialisation code:
(There is a special box called "add your own javascript", there is the initialisation code.)
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php"
} );
} );[/code]
Please, can you help me, where is the problem?
Thank you very much.
dingo
This discussion has been closed.
Replies
Allan
Thank you for your answer.
I know firebug, but not how to check the XHR with it, sorry!
Will donate now! ;)
The initialasation code is visible on the page. This is also not normal for sure...
http://img841.imageshack.us/img841/241/bildschirmfoto20100718uq.png
This is the source code of the wordpress page:
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Konrad
<!--[if lte IE 8]><![endif]-->
.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}
Home
Konrad
Subscribe
Konrad
Ein weiterer WordPress-Blog
Konrad
[edit]
Comments on this entry are closed.
Get smart with the Thesis WordPress Theme from DIYthemes.
WordPress Admin
<!--[if lte IE 8]>
<![endif]-->
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php"
} );
} );
[/code]
Thanks for the donation :-)
To check the XHR in Firebug, open Firebug and look at the 'console' tab. Any remote requests will show up there.
However, I doubt there will be one at the moment, based on your screenshot and HTML. The Javascript code most certainly shouldn't be shown on the page! The code needs script tabs around it. Something like:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php"
} );
} );
[/code]
I've never used WordPress, so I'm not entirely sure how it operates, but it could be as simple as just putting those script tags in place.
Regards,
Allan
Added the javascript tags to the code and it is no more to see on the page. First problem solved. :)
Here you can see the firebug error message:
http://img197.imageshack.us/img197/4741/bildschirmfoto20100718u.png
In my opinion there is a problem with the directories of the server_processing.php file.
In the initialisation code we have this directory: [code]"sAjaxSource": "../examples_support/server_processing.php"[/code]
But the file "server_processing.php is located at: http://localhost/wordpress/dataTables-1.6 2/examples/examples_support/server_processing.php
Anyway, this is just my newbie-view of the problem :)
So along with your initialisation code you'll need to include DataTables itself. Something like:
[code]
[/code]
will hopefully get around that hurdle.
Allan
Hmmm.. This is the new source code:
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Konrad
<!--[if lte IE 8]><![endif]-->
.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}
Home
Konrad
Subscribe
Konrad
Ein weiterer WordPress-Blog
Konrad
[edit]
Comments on this entry are closed.
Get smart with the Thesis WordPress Theme from DIYthemes.
WordPress Admin
<!--[if lte IE 8]>
<![endif]-->
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php"
} );
} );
[/code]
http://img62.imageshack.us/img62/4741/bildschirmfoto20100718u.png
Does the table now initialise and say that there is no data, and show the 'processing' indicator? You've got jQuery, you've got DataTables and you got a table... actually looking at your code you don't...
You've got jQuery doing $('#example')... but there is no element with an ID of example, never mind it being a table! Have a look at the example code on this page: http://datatables.net/examples/data_sources/server_side.html
You need to put the HTML table in where you want it with the required number of columns etc.
Allan
But I dont understand what you mean.
As I see it: jQuery is OK, DataTables is OK, but there is no HTML table on my site.
Now I put this HTML Code, (changed according to the fields in my MySQL database) on the wordpress page and it should work.
Is this what mean with the previous post?
[code]
Rendering engine
Browser
Platform(s)
Engine version
CSS grade
Loading data from server
Rendering engine
Browser
Platform(s)
Engine version
CSS grade
[/code]
When you now load the page it should initialise that table (you can tell if it has done so since DataTables will add the filtering input, etc). When it does that it will also send out an XHR request (which you will see in the firebug console) asking the server for data. Is that happening?
Allan
Please see the Firebug console screenshot:
http://img805.imageshack.us/img805/4741/bildschirmfoto20100718u.png
That means your path "../examples_support/server_processing.php" is wrong.
Perhaps it should be: /konrad2/dataTables-1.6/examples/examples_support/server_processing.php ? Not sure on the set up of your server/paths, so this might not be quite right.
Allan
Path is changed, no 404 error now, but a new one:
http://img204.imageshack.us/img204/4741/bildschirmfoto20100718u.png
"Could not select database kontab"
kontab is the name of the table into the database. ;)
Once this server-side error is taken care of, you should get information from the database put into the array and returned. You could try adding mysql_error() to my "Could not select database" string - which should give you a little bit more information to go on.
Allan
But I believe this is now a small problem.
What I dont understand is, you have no field for the database name, only for the table name. Is this correct?
Thank you so much for your great help and patience with a newbie!!
Regards
dingo
You need to modify all of the following information:
[code]
$aColumns = array( 'engine', 'browser', 'platform', 'version', 'grade' );
$sIndexColumn = "id";
$sTable = "ajax";
$gaSql['user'] = "";
$gaSql['password'] = "";
$gaSql['db'] = "";
$gaSql['server'] = "localhost";
[/code]
The db name and the table name are both in there and required. Certainly without a db name it won't be able to connect to the db :-)
Does mysql_error() show anything interesting?
Allan
This is my code:
[code]
$sIndexColumn = "id";
$sTable = "ajax";
/* Database connection information */
$gaSql['user'] = "USERNAME";
$gaSql['password'] = "PASSWORD";
$gaSql['db'] = "TABLE-NAME";
$gaSql['server'] = "SERVER OF DB";
[/code]
You write I should include the db name AND the table name. Whats the field "db" in the above code for? I think it is the table name?
But where to put the db name?
By now this part was not in the file: (!)
[code]
$sTable = "ajax";
[/code]
I was not able to get the mysql_error() working.
[code]
$sIndexColumn = "id";
$sTable = "TABLE-NAME";
/* Database connection information */
$gaSql['user'] = "USERNAME";
$gaSql['password'] = "PASSWORD";
$gaSql['db'] = "DATABASE NAME";
$gaSql['server'] = "SERVER OF DB";
[/code]
Also, 34'000 records won't be a problem. It should cope with many millions!
Allan
http://img827.imageshack.us/img827/593/bildschirmfoto20100718uz.png
I dont believe all this...
What is the name of your database, and what is the name of your table? Does the 'ajax' table exist if you look at it through your SQL manager interface (phpMyAdmin for example).
Allan
There is no table "ajax", for sure.
The name of the database is "rozuch_konrad"
The name of the table inside the db is "kontab"
I have all this data added to the file according to your instructions. This is 100% correct.
To be sure that is not a connection problem to the database (hosted on another server) I have copied the database and stored it locally. The error message in the console is still the same.
I presume you now then have:
$sTable = "kontab";
$gaSql['db'] = "rozuch_konrad";
With that are you still getting the same error? I'd suggest making a simple PHP script which will make the connection and do a simple 'SELECT', echoing out the results. This will take DataTables out of the equation, as it appears to be a db connection issue at the moment which needs to be resolved, or perhaps just different usage of the demo script.
Allan
$sTable = "kontab";
$gaSql['db'] = "rozuch_konrad";
Dont know what you mean exactly with the PHP script.
Thank you again for the help by now!
uncaught exception: [Exception... "'[JavaScript Error: "json is null" {file: "http://localhost/konrad2/dataTables-1.6/media/js/jquery.dataTables.min.js" line: 291}]' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)" location: "native frame :: :: :: line 0" data: yes]
Try this little PHP script:
[code]
<?php
$sTable = "kontab";
$gaSql['user'] = "XXXXXXXXX";
$gaSql['password'] = "XXXXXXXXX";
$gaSql['db'] = "rozuch_konrad";
$gaSql['server'] = "localhost";
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server: '.mysql_error() );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'].": ".mysql_error() );
$result = mysql_query( "SELECT * FROM ".$sTable, $gaSql['link'] )
or die ("Couldn't select from database: ".mysql_error() );
echo mysql_num_rows( $result )." rows selected";
?>
[/code]
It will test the connection to your database. If it doesn't work, then it's the DB connection that is going wrong somewhere. You need to change the user name and password ("XXXXXXXXX") obviously :-). Load it in a web-browser and let me know what is displayed on screen.
Allan
thank you for the script!
I will try this tomorrow and let you know the result.
My girlfriend is at home now, cannot sit in front of the computer now, otherwise she will kill me! :)
Thank you
Regards
dingo
Loaded the script into firefox, please see the screenshot here:
http://img826.imageshack.us/img826/4008/bildschirmfoto20100719uk.png
I think goodnews, right? :)