Server side script coming up with blank page (using Ampps)

Server side script coming up with blank page (using Ampps)

spidogrspidogr Posts: 23Questions: 9Answers: 0
edited June 2021 in DataTables 1.10

Server side script coming up with blank page (using Ampps)

Not sure if I can create a test case when a dB is involved.

I tried to follow this example and I downloaded the ssp.class.php from here and removed the 4 lines as instructed.

This is my html

<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="datatables.min.css"/> 
<script type="text/javascript" src="jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="datatables.min.js"></script>
<script>
$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "server_processing.php"
    } );
} );
</head>
<body>
<table id="example" class="display" style="width:100%">
<thead><tr>
<th>English</th>
<th>Greek</th>
</tr>
</thead>
</table>

Both server_processing.php and ssp.class.php are in the same folder as the html file.

This is my server processing file

$table = 'mytable';

// Table's primary key
$primaryKey = 'id';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
    array( 'db' => 'English', 'dt' => 0 ),
    array( 'db' => 'Greek',  'dt' => 1 )
);

// SQL server connection information
$sql_details = array(
    'user' => 'root',
    'pass' => 'mysql',
    'db'   => 'gloss',
    'host' => 'localhost'
);

and this is my dB screenshot https://ibb.co/5KGcB6f

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Your $(document).ready function is missing a closing script tag.

  • spidogrspidogr Posts: 23Questions: 9Answers: 0
    edited June 2021

    Thanks!

    Now I get:

    DataTables warning: table id=example - An SQL error occurred: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list'

    And I can see in server_processing.php

    // Table's primary key
    $primaryKey = 'id';

    I try to add Index in one of the columns but it will give the error

    1062 - Duplicate entry 'acoustic shock' for key 'PRIMARY'

    How can I have the index and allow duplicate entries in a column?

  • spidogrspidogr Posts: 23Questions: 9Answers: 0

    I added an id column and it worked after using

        ALTER TABLE `mytable` DROP INDEX `PRIMARY`;
        ALTER TABLE `mytable` ADD COLUMN `id` BIGINT(11) NOT NULL FIRST;
        ALTER TABLE `mytable` MODIFY COLUMN `id` BIGINT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT;
    

    My original SQL to create the table was

    CREATE TABLE mytable(
       English VARCHAR(255) NOT NULL PRIMARY KEY
      ,Greek   VARCHAR(255) NOT NULL
    );
    

    What should it be like to include the id column?

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

    Change $primaryKey = 'id'; to be:

    $primaryKey = 'English';
    

    Your table already has a primary key, so you can use that.

    Allan

Sign In or Register to comment.