Button to export result to mysql database

Button to export result to mysql database

fazaseikofazaseiko Posts: 1Questions: 1Answers: 0

i want to create 1 function or script that could export the result from my datatable and import automatically to my mysql database. im using php and my sql database. i dont have strong coding coding backgroup. can u please provide example so i can refer?

this is how my script look like

this is my script

    $(document).ready(function () {
        //Only needed for the filename of export files.
        //Normally set in the title tag of your page.
        document.title = "Detail by Job";
        // Create search inputs in footer
        $("#example tfoot th").each(function () {
            var title = $(this).text();
            $(this).html('<input type="text" placeholder="' + title + '" />');
        });
        // DataTable initialisation
        var table = $("#example").DataTable({
            dom: '<"dt-buttons"Bf><"clear">lirtp',
            paging: true,
            autoWidth: true,
            buttons: [
                "colvis",
                "copyHtml5",
                "csvHtml5",
                "excelHtml5",
                "pdfHtml5",
                "print"
            ],
            initComplete: function (settings, json) {
                var footer = $("#example tfoot tr");
                $("#example thead").append(footer);
            }
        });

        // Apply the search
        $("#example thead").on("keyup", "input", function () {
            table.column($(this).parent().index())
            .search(this.value)
            .draw();
        });
    });

and this is for php file

        <tr>
            <td> <?php print $i++ ?> </td> 
            <td> <?php print strtoupper($district) ?> </td>
            <td> <?php print strtoupper($dma) ?> </td>
            <td> <?php print $rows_ql1["job_id"] ?> </td>            
            <td> <?php print $rows_ql1["contractor_assigned_date"] ?> </td>
            <td> <?php print $rows_ql1["contractor_date_submit"] ?> </td>
            <td> <?php print $date_mnf1 ?> </td>
            <td> <?php print $date_mnf2 ?> </td>
            <td> <?php print number_format($healthy_mnf1,2) ?> </td>
            <td> <?php print number_format($healthy_mnf2,2) ?> </td>
            <td> <?php print number_format(($healthy_mnf1-$healthy_mnf2),2) ?> </td>
        </tr>

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    You would want to export as a 'CSV file, and then have another script that converts that into SQL statements. That's beyond the scope of this forum, it would be worth asking on StackOverflow or a more relevant site.

    Colin

Sign In or Register to comment.