PHP generated table not working

PHP generated table not working

graphicusgraphicus Posts: 3Questions: 1Answers: 0
edited October 2022 in Free community support

I use generated PHP tables populated to SQL data. These work fine on their own but when I try to implement datatables as a responsive solution they fail. Here's the SQL query/PHP:

<?php 
$order_table = mysqli_query($conn,"SELECT * FROM $VariantsTable WHERE ProductPage='".$PageQuery."' ORDER BY Sort");
echo "<table id='tableOrdering' class='display'>";
$i = 0;
while($row = $order_table->fetch_assoc())
{
    if ($i == 0) {
      $i++;
      echo "<thead class='tableHeader'><tr>";
      foreach ($row as $key => $value) {
        echo "<th>" . $key . "</th>";
      }
      echo "</tr></thead><tbody>";
    }
    echo "<tr>";
    foreach ($row as $value) {
      echo "<td>" . $value . "</td>";
    }
    echo "</tr>";
}
echo "</tbody></table>";
mysqli_close($conn);

<?php
>
```
?>


The datatable configuration files are: 

(in the header):

```html
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.12.1/r-2.3.0/sb-1.3.4/sp-2.0.2/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.12.1/r-2.3.0/sb-1.3.4/sp-2.0.2/datatables.min.js"></script> 

(in the footer)

$(document).ready( function () {
$('#tableOrdering').DataTable( {
    responsive: true
} )
});

I've tested this with static tables and they work as expected, but implementing the generated table just echo the opening and closing

tags then crash the page.

Any help much appreciated.

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • graphicusgraphicus Posts: 3Questions: 1Answers: 0

    That should be -- the opening and closing 'table' tags --

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

    When you say it crashes, to you mean a Chrome "Oh snap" error or something like that? Or is there some other error message?

    How large is your data set? How big is the generated HTML page?

    Allan

  • graphicusgraphicus Posts: 3Questions: 1Answers: 0

    Thanks very much for the response:

    "It crashes": the page stops rendering at that point. Everything above the table is fine. It echoes the opening and closing table tags but there is no content inside them, and nothing renders below that.

    The test page size is 433.7 KB

    I'm not too sure how to get the dataset size, but there are about 60 products in the database, with values and variables across 11 tables. The biggest table has 34 columns.

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

    That sounds like a server-side issue to me - possibly that there are no records matching the query. Check your server's error logs to see if there are any PHP errors shown.

    You could also add:

    ```php
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    <?php > ``` ?>

    at the top of your PHP file which should force any errors to be output.

    Allan

Sign In or Register to comment.