I have a table with a list of players, by clicking on the players row I would like to display a table below with the player’s details. I can do it but when I click the table with the players… display twice player’s table and below the table with the details. Where is the error? Thanks
<?php
require_once('./php/config.php');
$q_classifica = "SELECT * FROM giocatori ORDER BY punti DESC";
if($r_classifica = $conn->query($q_classifica))
{
$indice=1;
echo '<div class="box-class1 roboto-bold">
<table style="width: 380px; height: 60px;" border="0" cellpadding="2" cellspacing="2" class="scrolldown prova">
<thead><tr>
<th style="width: 60px"></th>
<th style="width: 205px"></th>
<th style="width: 86px"></th>
<th style="width: 29px"></th>
</tr></thead><tbody>';
while ($row1 = $r_classifica->fetch_array())
{
echo '
<tr class="mia" id="' . $row1['ID'] . '">
<td style="width: 60px"><a href="https://wa.me/' . $row1['cell'] . '?text=Ciao...%20vorrei sfidarti!!!%20al%20torneo"><img style="width: 17px; height: 19px;" alt="ball" src="ball.png"></a> ' . $indice . '</td>
<td style="width: 205px">' . $row1['nome'] . '</td>
<td style="width: 86px">' . $row1['punti'] . '</td>';
$infortunio = $row1['infortunio'];
if($infortunio==si){echo '<td style="width: 29px"><img style="width: 30px; height: 22px;" alt="infortunato" src="ambulanza.png"></td></tr>';}
else{
echo '<td></td></tr>';
}
$indice++;
}
echo "</tbody></table></div>";
}else{
echo "Errore impossibile eseguire la query $q_classifica. " . $conn->error;
}
?>
<script>
$(document).ready(function(){
$('.mia').click(function(){
id_player = $(this).attr('id')
$.ajax({url: "home.php",
method:'post',
data:{player_id:id_player},
success: function(result){
$(".modbody").html(result);
}});
// $('#myModal').modal("show");
})
})
</script>
<div class="modbody">
<?php
if(isset($_POST["player_id"]))
{
$output = '';
$a_giocatore = "SELECT nome FROM giocatori WHERE giocatori.id = '".$_POST["player_id"]."'";
$result = $conn->query($a_giocatore);
while ($row = mysqli_fetch_assoc($result))
{
$giocatore= $row['nome'];
}
$output .= '
<H2><div style="text-align: center;" class="roboto-black-italic box-giocatore1">' . $giocatore . '</H2></div>';
$q_partita = "SELECT * FROM partite WHERE (giocatore_1 = '$giocatore' OR giocatore_2 = '$giocatore') AND (vittoria = '$giocatore') AND (punteggio IS NOT NULL) ORDER BY data DESC";
if($r_partita = $conn->query($q_partita))
{
$output .= '
<table style="text-align: center;" border="0" cellpadding="2" cellspacing="1" class="vinte">
<thead>
<tr>
<th style="vertical-align: top; width: 105px;"><br></th>
<th style="vertical-align: top; width: 105px;"><img alt="up" src="vi.png"><br></th>
<th style="vertical-align: top; width: 70px;"><br></th>
<th style="vertical-align: top; width: 70px;"><br></th>
</tr>
</thead>';
while ($row1 = $r_partita->fetch_array())
{
$data = $row1['data'];
$timestamp_data = strtotime($data); // converte data in formato leggibile a video, cercare modo di mettere nomi in ITA
$formato = 'j M Y';
$resultd = date($formato, $timestamp_data); // converte data in formato leggibile a video, cercare modo di mettere nomi in ITA
$output .= '
<tbody>
<tr>
<td class="roboto-regular-italic"><font size="1">' . $row1['giocatore_1'] . '</font></td>
<td class="roboto-regular-italic"><font size="1">' . $row1['giocatore_2'] . '</font></td>
<td class="roboto-regular-italic"><font size="1">' . $row1['punteggio'] . '</font></td>
<td class="roboto-regular-italic"><font size="1">' . $resultd . '</font></td>
</tr>';
}
$output .= '
</tbody>
</table>';
}
$q_partita2 = "SELECT * FROM partite WHERE (giocatore_1 = '$giocatore' OR giocatore_2 = '$giocatore') AND (sconfitta = '$giocatore') AND (punteggio IS NOT NULL) ORDER BY data DESC";
if($r_partita2 = $conn->query($q_partita2))
{
$output .= '
<table style="text-align: center;" border="0" cellpadding="2" cellspacing="1" class="perse">
<thead>
<tr>
<th style="vertical-align: top; width: 105px;"><br></th>
<th style="vertical-align: top; width: 105px;"><img alt="up" src="sc.png"><br></th>
<th style="vertical-align: top; width: 70px;"><br></th>
<th style="vertical-align: top; width: 70px;"><br></th>
</tr>
</thead>';
while ($row1 = $r_partita2->fetch_array())
{
$data2 = $row1['data'];
$timestamp_data2 = strtotime($data2); // converte data in formato leggibile a video, cercare modo di mettere nomi in ITA
$formato2 = 'j M Y';
$result2 = date($formato2, $timestamp_data2); // converte data in formato leggibile a video, cercare modo di mettere nomi in ITA
$output .= '
<tbody>
<tr>
<td class="roboto-regular-italic"><font size="1">' . $row1['giocatore_1'] . '</font></td>
<td class="roboto-regular-italic"><font size="1">' . $row1['giocatore_2'] . '</font></td>
<td class="roboto-regular-italic"><font size="1">' . $row1['punteggio'] . '</font></td>
<td class="roboto-regular-italic"><font size="1">' . $result2 . '</font></td>
</tr> ';
}
$output .= '
</tbody>
</table>';
}
echo $output;
unset ($giocatore);
}
?>
</div>
I tried to send the url via post in the same page but the first table appears twice. I would like to do this process without reloading the page, thanks