MySQL PHP

MySQL PHP

josh10josh10 Posts: 10Questions: 0Answers: 0
edited July 2009 in General
I am completely new to jquery and this plugin looks like everything I have been looking for. I have been using SPRY, but I have a large dataset and it takes forever to load. My question is what is the syntax to call and display columns from MySQL. I have created a php file to connect to MySQL and display my table. How do I call that file and then call those rows in the table? I would greatly appreciate any help. Thanks.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi josh10,

    Have you seen the server-side processing example that DataTables 1.5 (beta) comes with? http://datatables.net/1.5-beta/examples/data_sources/server_side.html It sounds like this might help you in your quest...

    Regards,
    Allan
  • josh10josh10 Posts: 10Questions: 0Answers: 0
    Yeah I've already looked through all the examples. I already have that file created. I simply need to know the syntax for each table column. Thanks again.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi josh10,

    I'm not quite sure what you mean by the syntax for each table column? Each table column is just a string in a Javascript array. If you have a look at how my script is passing data around, this might help (Firebug will also help, given that it shows what is actually passed around). Also this post might be of some use, detailing what data is passed to the server, and from it: http://datatables.net/forums/comments.php?DiscussionID=53 . Full documentation for that will be available soon.

    Regards,
    Allan
  • josh10josh10 Posts: 10Questions: 0Answers: 0
    Ok, I'm posting my code below (which is really just a variation on the example). All it ever says is "Loading data from server". But it never loads my data. However in the server_processing.php file I am seeing that it is connecting and grabbing all the rows in my table. That is why I assumed there was something I was missing in the html file in the example. So here goes.
    [code]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">





    DataTables example

    @import "../../media/css/demo_page.css";
    @import "../../media/css/demo_table.css";





    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "../examples_support/server_processing.php"
    } );
    } );





    DataTables server-side processing example







    Customer_Ticket_No




    Loading data from server




    Customer_Ticket_No






    [/code]
    What can I change in this to see my data?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi josh10,

    A couple of things from this then:

    1. You've included jQuery twice (this is my fault - my demo code has this as well - I think I've corrected them all now though)
    2. You only have one column (the th) so if you have more than one column of information returned from the server it will reject it - the columns much match in the HTML and the server return.
    3. You have a colspan=5 but only one column!

    Regards,
    Allan
  • josh10josh10 Posts: 10Questions: 0Answers: 0
    Yeah I just included the one column because I am just trying to get it to work so trying to stay simple. Ok here is my code now. I'm including the server_side.html and then the server_processing.php. I am still only getting the "Loading data from server".

    [code]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">





    DataTables example

    @import "../../media/css/demo_page.css";
    @import "../../media/css/demo_table.css";




    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "../examples_support/server_processing.php"
    } );
    } );





    DataTables server-side processing example







    Customer_Ticket_No




    Loading data from server




    Customer_Ticket_No






    [/code]
  • josh10josh10 Posts: 10Questions: 0Answers: 0
    And the php file

    [code]
    <?php
    /* MySQL connection */
    include( $_SERVER['DOCUMENT_ROOT']."/Connections/datatables.php" ); /* ;-) */

    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );

    /* Paging */
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) )
    {
    $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
    mysql_real_escape_string( $_GET['iDisplayLength'] );
    }

    /* Ordering */
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Thanks for your code. This confirms what I said earlier - your HTML has only one column in it, while your server-side process is returning five columns for each row. I think that's your problem there. Just add a couple more TH and TD elements to the table.

    Regards,
    Allan
  • josh10josh10 Posts: 10Questions: 0Answers: 0
    WOW!!! This worked great. I had overlooked renaming the mysql columns in the php file from your example to my column names. This is like night and day on load time over what I was using with SPRY. Really impressed. Thanks for the quick responses and patience with a beginner in jquery, I really appreciate it!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Excellent stuff - great to hear this did the trick for you and that the loading time is looking good!

    Regards,
    Allan
  • sonytasonyta Posts: 3Questions: 0Answers: 0
    just test
    [code]
    I am still only getting the "Loading data from server".
    [/code]
This discussion has been closed.