I'm quite new to php, however, my connection to the server is successful, what hinders me is to make a table in HTML with the fields that are extracted from the connection and I want the results to show me the table and something that I'm doing badly because at the top it shows me the results of the connection and below the table. My goal is for the table to show me the results of each field connected to each other! Here I show you my code
<?php
$servername = "xxxxxx";
$username = "xxxxx";
$password = "";
$db = "xxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$mysqli = new mysqli("xxxxx", "xxxx", "", "xxxxx");
/* comprueba la conexión */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* devuelve el nombre de la base de datos actualmente seleccionada */
if ($result = $mysqli->query("SELECT DATABASE(chat)")) {
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);
$result->close();
}
/* cambia de test bd a world bd */
$mysqli->select_db("xxxx");
/* devuelve el nombre de la base de datos actualmente seleccionadae */
if ($result = $mysqli->query("SELECT DATABASE()")) {
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);
$result->close();
}
/*selecciona campos de la tabla*/
$sql = "SELECT date, threads, operator_msgs, user_msgs, missed_threads, avg_waiting_time, invitations_sent, invitations_accepted, invitations_rejected, invitations_ignored FROM cgchat";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "date: " . $row["date"]. " threads: " . $row["threads"]. "Operator messages: " . $row["operator_msgs"]. " User messages: " . $row["user_msgs"]. "Missedthreads " . $row["missed_threads"]. "Average waiting time " . $row["avg_waiting_time"]. "Sentinvitations: " . $row["invitations_sent"]. " Acceptedinvitations: " . $row["invitations_accepted"]. "Rejectedinvitations: " . $row["invitations_rejected"]. " Ignoredinvitations: " . $row["invitations_ignored"]. "<br>";
}
} else {
echo "0 results";
}
$mysqli->close();
?>
<!DOCTYPE html>
<html>
<head>
<FORM action="conex.php" method="post">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>DataTables example - Multiple tables</title>
<link rel="shortcut icon" type="image/png" href="/media/images/favicon.png">
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.datatables.net/rss.xml">
<link rel="stylesheet" type="text/css" href="/media/css/site-examples.css?_=6e5593ad4c5375eef5d919cfc10a0a54">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
<style type="text/css" class="init">
div.dataTables_wrapper {
margin-bottom: 3em;
}
</style>
<script type="text/javascript" src="/media/js/site.js?_=88b8e26b7e3dd4eee69f199f9880a0e0">
</script>
<script type="text/javascript" src="/media/js/dynamic.php?comments-page=examples%2Fbasic_init%2Fmultiple_tables.html" async>
</script>
<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.4.js">
</script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js">
</script>
<script type="text/javascript" language="javascript" src="../resources/demo.js">
</script>
<script type="text/javascript" class="init">
$(document).ready(function() {
$('table.display').DataTable();
} );
</script>
</head>
<body class="wide comments example">
<a name="top" id="top"></a>
<div class="form-header">
<div class="form-header-inwards"></div>
</div>
<table id="" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Date</th>
<th>Threads</th>
<th>Operator messages</th>
<th>User messages</th>
<th>Missedthreads</th>
<th>Average waiting time</th>
<th>Sentinvitations</th>
<th>Acceptedinvitations</th>
<th>Rejectedinvitations</th>
<th>Ignoredinvitations</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Total</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
the result that appears in the upper part of the image I want you to show it to me but in the table that is shown, according to what I want to do in a single file, because if it were two, I just need a little help to explain how I would do it.?
Thanks