Minervaz Mine Minervaz Mine - 30 days ago 20
PHP Question

how to split the data from $_POST var_dump in php

hi guy's this is my first time using

var_dump
in php function.
i am really don't know how to split the data from that
var_dump

maybe someone can help me to give an example for split that data. i hope the method is simple for i can understand. i have try to search it in this forum and i can understand it.

this is the data i have got from `var_dump
Data from Var_dump

please give me a simple example for that.
an please explain it for me.
i just use this code for get the data. because its my 1st time.

<?php
include('../../Connections/koneksi.php');
$tableData = var_dump($_POST);

echo $array;
?>


This is the actual data
http://jsfiddle.net/minervaz/us4a9gkL/

Answer Source
  • You can't use echo to display an object or array.So use var_dump() or print_r()

Javascript code :

<script type="text/javascript">
    $(document).on('click','#display_data',function(e){
    var convertTableToJson = function()
        {
            var rows = [];
            $('.table-bordered tr:has(td)').each(function(i, n){
                var $row = $(n);
                rows.push([
                    $row.find('td:eq(0)').text(),
                    $row.find('td:eq(1)').text(),
                    $row.find('td:eq(2)').text(),
                    $row.find('td:eq(3)').text(),
                    $row.find('td:eq(4)').text(),
                    $row.find('td:eq(5)').text(),
                    $row.find('td:eq(6)').text(),
                    $row.find('td:eq(7)').text(),
                ]);
            });
            return JSON.stringify(rows);
        };
   var data = convertTableToJson();
    $.ajax({
    data: { 'table-bordered': data },  
    type:"POST",
    url:"../php/tagihan/save_data.php",
            success: function(data){
                //alert(JSON.stringify(data));
                console.log(data);
            }            
    });

});
</script>

PHP CODE:

if(isset($_POST['table-bordered'])){
    $array=json_decode($_POST['table-bordered'],true);
    print_r($array);


}

Output

Array
(
    [0] => Array
        (
            [0] => 101200
            [1] => WCB
            [2] => 101
            [3] => 5006540050
            [4] => 1
            [5] => 10.08.2017
            [6] => 23.970
            [7] => KG
        )

    [1] => Array
        (
            [0] => 101200
            [1] => WCB
            [2] => 101
            [3] => 5006539985
            [4] => 1
            [5] => 10.08.2017
            [6] => 42.970
            [7] => KG
        )

)