Newbie - HELP!

Newbie - HELP!

prithiviprithivi Posts: 8Questions: 0Answers: 0
edited May 2011 in General
i am attempting to use the DataTables plugin but cant quite work it all out. right bits in the header... calling a php file to query the server... nothing displays except the column names. I am REALLY new to JQuery but have experience in php. Any ideas where i might be going wrong? help much appreciated. thanks in advance.

Replies

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

    I'm going to need a little more information that than to be able to help I think :-). What kind of data source are you using - are you just trying to enhance an HTML table for example? What initialisation are you using for DataTables? It would be very helpful if you could give me a link to your page.

    Allan
  • prithiviprithivi Posts: 8Questions: 0Answers: 0
    Hey Alan, thanks for the reply.
    its on an internal server at the moment.
    I have this in the header:

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


    then entered the relevent details into server_processing....

    and then i am embarrassed to say i hit a bit of a wall.
    i didn't know how to call up an instance of your datagrid in the page...
    so i looked at the source of a page on your site but still couldn't get it to work.
    yeah - i know its all really basic but i think its my blond hair holding me back.
  • prithiviprithivi Posts: 8Questions: 0Answers: 0
    sorry...
    blond again!
    its calling a table in mysql
  • prithiviprithivi Posts: 8Questions: 0Answers: 0
    as you identified i am trying to improve my table skills...
    heres what i am trying to improve:
    [code]
    <?php
    $sql2 = "SELECT COUNT(id) FROM suggestions";
    $rs_result2 = mysql_query($sql2);
    $row2 = mysql_fetch_row($rs_result2);
    $total_records = $row2[0];
    $total_pages = ceil($total_records / $r);
    ?>


     
     


    Date
    Notes
    Completed
    Page


    <?php
    for ($j=1; $j<=$total_pages; $j++) {
    echo "".$j." | ";
    } ;
    ?>


    <?php
    $jj== 1;
    while ($row = mysql_fetch_assoc($rs_result)) {
    $jj++;
    $id = $row["id"];
    $comp = $row["complete"];
    if($comp == 'Y'){$comp1 = 'Yes';}else{$comp1 = 'No';}
    if($jj % 2){echo "";}else{echo "";}
    ?>
    <? echo $row["date"]; ?>
    <? echo $row["notes"]; ?>
    <? echo $comp1; ?>
    <? echo "view" ?>

    <?php
    };
    ?>

    Page

    <?php

    for ($i=1; $i<=$total_pages; $i++) {
    echo "".$i." | ";
    } ;
    ?>
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Heh - no worries. This is the schema that my demo scripts use: http://datatables.net/development/server-side/sql . Obviously you'll want to customise the parameters at the top of the page though in order to use your own data. From there, looking at the JSON return in Firebug can be helpful to resolve any issues.

    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Posts overlapped there. So your PHP above is outputting an HTML table - is that correct? In which case, you aren't using server-side processing, and probably don't want to (unless you've got 10'000+ rows of data). There is a discussion here of the data source types that DataTables can consume: http://datatables.net/usage/#data_sources

    So, assuming you are just enhancing a plain HTML table you would want to do something like that shown in this example: http://datatables.net/examples/basic_init/zero_config.html

    Allan
  • prithiviprithivi Posts: 8Questions: 0Answers: 0
    Allan, thanks again. Yes enhancing plain html. however as you can see it takes data from mysql and iterates filling the table. i cant see how to do it. if its really obvious - forgive me - i feel so stupid!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Include the following at the top of your page:

    [/code]

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




    $(document).ready(function() {
    $('#example').dataTable();
    } );

    [/code]
    You may need to alter the paths for the include files. You might also need to change the selector for the dataTable() initialisation.

    Allan
  • prithiviprithivi Posts: 8Questions: 0Answers: 0
    Hi Allan, thanks for that. got all the stuff at the top its the dataTable() initialisation i cant get.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    In what way can't you get it? Is it giving a Javascript error or something?

    Allan
  • prithiviprithivi Posts: 8Questions: 0Answers: 0
    Hi Allan, The reason i cant get it to work is that i am new and dont quite understand how to. I did apologise and explain this at the beginning. could i ask to its us in a raw unprocessed file or could you tell me how to call it. thank you in advance.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It's no problem - we all have to start somewhere. The raw unprocessed file that I use for my examples is here: http://datatables.net/examples/basic_init/zero_config.html . Right click and select "View source" - that's the plain HTML for the page - you will see a TABLE element in there with the data. Then using the code that I posted above, jQuery and DataTables are included, and than DataTables initialised. The DataTables initialisation code above is simply $('#example').dataTable(); (i.e. a jQuery selector for the 'example' element, and then call DataTables).

    Allan
  • prithiviprithivi Posts: 8Questions: 0Answers: 0
    Hi Allan,

    It was a long weekend and i was extremely tired and blonde!
    I took it all back to basics and resolved the problem.
    a combination of php mysql jquery and some sleep.

    code enclosed in case someone else needs a light shining in their mental darkness.

    Thanks again for your assistance.;))



    [code]



    date
    notes
    status
    actions





    <?php

    include("../../connection/connectdb.php");

    $query = "SELECT * FROM suggestions ";
    $result = mysql_query($query);
    $num = mysql_num_rows ($result);

    if ($num > 0 ) {
    $i=0;


    while ($i < $num) {
    $uid = mysql_result($result,$i,"uid");
    $date = mysql_result($result,$i,"date");
    $notes = mysql_result($result,$i,"notes");
    $complete = mysql_result($result,$i,"status");
    $id = mysql_result($result,$i,"id");


    echo "";
    echo "$date";
    echo "$notes";
    echo "$status";
    echo "view";
    echo "";



    ++$i; }
    echo ""; } else { echo "The database is empty"; }?>



    date
    notes
    status
    actions



    [/code]
This discussion has been closed.