0
I’m making a site for a futsal club and created a table with the names of the players in php that will fetch information from a database and wanted to, if possible, make links through the names to pages with more detailed information about the players. This is code for creating tables:
<?php
$servername ="localhost";
$username="root";
$password="";
$dbname="casaldogrilo";
//cria conexão
$conn = new mysqli($servername, $username, $password, $dbname);
// verifica conexão
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM juniores order by Nome ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table style='width:100%' height='100%'>
<tr>
<th>Nome</th>
<th>Data_Nasc</th>
<th>Idade</th>
<th>Nacionalidade</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>
<td align='center'>".$row["Nome"]."</td>
<td align='center'>".$row["Data_Nasc"]."</td>
<td align='center'>".$row["Idade"]."</td>
<td align='center'>".$row["Nacionalidade"]."</td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
Players have an id on the BD table?
– Miguel
In the BD table players only have name, date of birth and nationality
– Miguel Sousa
What makes a player unique in the table? At least you should include a field
id
at auto-increment on the table, so that each player has a unique id. Because if two players have the same name/date of birth/nationality, which one do you want?– Miguel
After including the id field, how should php code look like?
– Miguel Sousa
I’m responding to that. It’s a bit big the answer. Do that and then come that you should be. Leave in auto-increment the id column
– Miguel
And by the way, you can include the code of your connection (no passwords) just to see how you’re structuring it
– Miguel
Amigo @Miguelsousa put the codes only in your question, leave code in the comments may confuse someone , Miguel be responding so I suggest you wait for the suggestions and then ask questions, it may be that the answer really takes a little , but wait a little.
– Ricardo Lucas
I answered below, I hope it fits
– Miguel
(I’m sorry if I’m being ignorant) I already put the above codes but then I get the following error: Notice: Undefined index: id in C: wamp www Pap juvenis.php on line 75. Am I doing something wrong? @Miguel
– Miguel Sousa