php pdo, reading

php pdo, reading

TheodorusTheodorus Posts: 7Questions: 3Answers: 0

From https://wijkvisiefraneker.nl/users/members
```
$db->query("SET NAMES utf8");
$data = $db->query("SELECT genre, first_name, number_of_people FROM members ORDER BY members_id DESC")->fetchAll(PDO::FETCH_ASSOC);

header("content-type:application/json");
echo json_encode($data);
````

to https://wijkvisiefraneker.nl/users/tmp

What Do I wrong?

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    How/where are you accessing DataTables' Javascript?

  • TheodorusTheodorus Posts: 7Questions: 3Answers: 0
     $().ready(function() {
                $.fn.dataTable.ext.errMode = 'throw';
    
    
                var dataTable = $('#dataTable').DataTable({
                    ajax: 'https://wijkvisiefraneker.nl/users/members',
                    'aLengthMenu': [[100, 250, 500, -1], [100, 250, 500, 'All']],
                    'iDisplayLength': 100
                });
    
                setInterval(function() {
                    dataTable.ajax.reload();
                }, 5000);
            });
    
  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    No.
    You need a "script src.....etc" reference to DataTables in your HTML.

  • TheodorusTheodorus Posts: 7Questions: 3Answers: 0

    Yes I see, I have added the files and updated https://wijkvisiefraneker.nl/users/tmp

  • TheodorusTheodorus Posts: 7Questions: 3Answers: 0

    fixed.

    PHP:

    $db->query("SET NAMES utf8");
    $data = $db->query("SELECT genre, first_name, number_of_people FROM members WHERE status = 1 ORDER BY members_id ASC")->fetchAll(PDO::FETCH_ASSOC);
    
    header("content-type:application/json");
    echo json_encode(array('data' => $data), JSON_PRETTY_PRINT);
    

    JS:

    $().ready(function() {
                $.fn.dataTable.ext.errMode = 'throw';
    
    
                var dataTable = $('#dataTable').DataTable({
                    "order": [[ 1, "asc" ]],
                    ajax: 'file.php',
                    'aLengthMenu': [[100, 250, 500, -1], [100, 250, 500, 'All']],
                    'iDisplayLength': 100,
                    "columns": [
                        { "data": "genre" },
                        { "data": "first_name" },
                        { "data": "number_of_people" }
                    ]
                });
    
                setInterval(function() {
                    dataTable.ajax.reload();
                }, 5000);
            });
    
  • TheodorusTheodorus Posts: 7Questions: 3Answers: 0

    Hello, I want to add a linkt to the form like <a href="link">first_name</a>

    How can I make thas possable ?

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    use the render option in columns or columnDefs https://datatables.net/reference/option/columns.render

This discussion has been closed.