how to integrate datatables in simple php file?

how to integrate datatables in simple php file?

testowniktestownik Posts: 21Questions: 10Answers: 0

Forgive me the question, I'm not a php person.
How to structure php file with basic datatables configuration?

The only reason I use php is, because I'm reading external file, to fill the table data, so in essence I have something like this inside:

<tbody>
<?php include 'textfile.txt';?>
</tbody>

When I change the extension of the main/container file from html to php and send it to the server - browser seems to read php part, but ignores datatables.

Answers

  • markmcwmarkmcw Posts: 12Questions: 0Answers: 0

    Assuming that textfile.txt is formatted correctly, you'll need to echo it.

    echo file_get_contents("textfile.txt");

  • testowniktestownik Posts: 21Questions: 10Answers: 0

    It's not this. Here is where I am at the moment. Example shows local table data. I can't get it right, datatables are just ignored.

    <?php header(`Content-Type: text/html; charset=ISO-8859-2`) ?>
    <?php
    echo "<link rel=`stylesheet` type=`text/css` href=`jquery-ui.css`/>";
    echo "<link rel=`stylesheet` type=`text/css` href=`dataTables.jqueryui.min.css`/>";
    echo "<link rel=`stylesheet` type=`text/css` href=`buttons.jqueryui.min.css`/>";
    echo "<style type=`text/css` class=`init`></style>";
    echo "<script type=`text/javascript` language=`javascript` src=`jquery-3.3.1.min.js`></script>";
    echo "<script type=`text/javascript` language=`javascript` src=`jquery.dataTables.min.js`></script>";
    echo "<script type=`text/javascript` language=`javascript` src=`dataTables.jqueryui.min.js`></script>";
    echo "<script type=`text/javascript` language=`javascript` src=`dataTables.buttons.min.js`></script>";
    echo "<script type=`text/javascript` language=`javascript` src=`buttons.colVis.min.js`></script>";
    echo "<script type=`text/javascript` language=`javascript` src=`input.js`></script>";
    echo "<script type=`text/javascript` language=`javascript` src=`myconf.js` class=`init`></script>";
    ?>
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <style type="text/css">
    <!--
    td {background-color: #EBEBEB;}
    p {font-family: Arial, Helvetica, sans-serif;font-size: 9pt;margin-top: 0pt;margin-right: 5pt;margin-bottom: 0pt;margin-left: 5pt;}
    -->
    </style>
    <table width="800" border="0" cellspacing="2" cellpadding="2" align="center">
    <thead><tr>
    <th><p><b>kol1</p></th>
    <th><p><b>kol2</b></p></td>
    <th><p><b>kol3</b></p></th>
    <th><p><b>kol4</b></p></th>
    </tr></thead><tbody> <!-- table body -->
    <tr>
    <td nowrap><p>1</p></td>
    <td nowrap><p>2</p></td>
    <td nowrap><p>3</p></td>
    <td nowrap><p>4</p></td>
    </tr>
    </tbody>
    </table>
    </body>

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Thanks for your question. As noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    For example - I don't see where your DataTable is being initialised in the above. It might be in input.js or myconf.js but without a test case it is impossible to say.

    Allan

This discussion has been closed.