I'm trying to output some data from my database on a table using PHP. I've successfully connected my database using AWS but for some reason nothing shows up on the table. My guess is there's something wrong with the index.php file.
A little background. I found this template on a website (http://demo.phpjabbers.com/freescripts/mysql-search-table/search.php). I modified it so that I could output my data instead of the preset fields they put on it. All I did was change the names of the headers and add additional columns.
Any help is greatly appreciated.
Here's my code
index.php
<?php error_reporting(0); include("config.php"); ?><!DOCTYPE html> <html> <head> <title style="color:white">Cohort 5</title> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <title>MySQL table search</title> <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/fixedheader/3.1.7/css/fixedHeader.bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.5/css/responsive.bootstrap.min.css"> <link rel="stylesheet" href="datepicker/css/bootstrap-datepicker.min.css"> <style type="text/css" class="init"> tfoot input { width: 50%; padding: 3px; box-sizing: border-box; } .dataTables_wrapper .dataTables_filter { float: right; text-align: right; visibility: hidden; } #search_wrapper{ width: 175%; } table.dataTable > tbody > tr.child span.dtr-title{ display: none; } body{ background-image: url("1325771.jpg"); background-repeat: no-repeat; background-attachment: fixed; background-size: cover; } </style> <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script> <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script> <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap.min.js"></script> <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/fixedheader/3.1.7/js/dataTables.fixedHeader.min.js"></script> <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/responsive/2.2.5/js/dataTables.responsive.min.js"></script> <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/responsive/2.2.5/js/responsive.bootstrap.min.js"></script> <script src="datepicker/js/bootstrap-datepicker.min.js"></script> <script type="text/javascript" class="init"> $(document).ready(function() { // Setup - add a text input to each footer cell $('#search thead th').each( function () { var title = $(this).text(); $(this).html( ''+title+' <br><input type="text" class="filter" placeholder="Search '+title+'" />' ); } ); // DataTable var table = $('#search').DataTable({ responsive: true, initComplete: function () { // Apply the search this.api().columns().every( function () { var that = this; $( 'input', this.header() ).on( 'keyup change clear', function () { if ( that.search() !== this.value ) { that .search( this.value ) .draw(); } } ); } ); } }); $('.filter').on('click', function(e){ e.stopPropagation(); }); new $.fn.dataTable.FixedHeader( table ); $("#search th.datepicker input").datepicker({ format: "yyyy-mm-dd", }); } ); </script> </head> <body style="padding: 5px"> <article> <h1 style="color:white">Cohort 5</h1> <table id="search" class="table table-striped table-bordered display responsive nowrap" style="width: 100%" style="color:white"> <thead> <tr> <th style="color:white"><strong>db_ID</strong></td> <th style="color:white"><strong>Number</strong></td> <th style="color:white"><strong>Name</strong></td> <th style="color:white"><strong>MagSlope</strong></td> <th style="color:white"><strong>Diameter</strong></td> <th style="color:white"><strong>Albedo</strong></td> <th style="color:white"><strong>RotP</strong></td> <th style="color:white"><strong>BV</strong></td> <th style="color:white"><strong>UB</strong></td> <th style="color:white"><strong>SMASII</strong></td> <th style="color:white"><strong>Tholen</strong></td> </tr> </thead> <tbody> <?php $sql = "SELECT * FROM ".$SETTINGS["data_table"]; if ($result = $mysqli->query($sql)) { while ($row = $result->fetch_assoc()) { ?> <tr> <td><?php echo $row["db_ID"]; ?></td> <td><?php echo $row["Number"]; ?></td> <td><?php echo $row["Name"]; ?></td> <td><?php echo $row["MagSlope"]; ?></td> <td><?php echo $row["Diameter"]; ?></td> <td><?php echo $row["Albedo"]; ?></td> <td><?php echo $row["RotP"]; ?></td> <td><?php echo $row["BV"]; ?></td> <td><?php echo $row["UB"]; ?></td> <td><?php echo $row["SMASII"]; ?></td> <td><?php echo $row["Tholen"]; ?></td> </tr> <?php } } else { ?> <tr><td colspan="10">No results found.</td> <?php } ?> </tbody> <tfoot> <tr> <th style="color:white"><strong>db_ID</strong></td> <th style="color:white"><strong>Number</strong></td> <th style="color:white"><strong>Name</strong></td> <th style="color:white"><strong>MagSlope</strong></td> <th style="color:white"><strong>Diameter</strong></td> <th style="color:white"><strong>Albedo</strong></td> <th style="color:white"><strong>RotP</strong></td> <th style="color:white"><strong>BV</strong></td> <th style="color:white"><strong>UB</strong></td> <th style="color:white"><strong>SMASII</strong></td> <th style="color:white"><strong>Tholen</strong></td> </tr> </tfoot> </table> </article> </body> </html>
config.php
<?php /* Define MySQL connection details and database table name */ $SETTINGS["mysql_user"]='user'; $SETTINGS["mysql_pass"]='********'; $SETTINGS["hostname"]='host'; $SETTINGS["mysql_database"]='database'; $SETTINGS["data_table"]='table'; /* Connect to MySQL */ $mysqli = new mysqli($SETTINGS["hostname"], $SETTINGS["mysql_user"], $SETTINGS["mysql_pass"],$SETTINGS["mysql_database"]); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } ?>
https://stackoverflow.com/questions/67012292/php-no-data-available-in-table April 09, 2021 at 05:46AM
没有评论:
发表评论