My purpose is when we click on the button info, we have more info displayed in the same page.
But, we need to get info’s client for the good client.
With my structure of td echo php, i am lost.
For example, i want to display info only for id_client 1
My php HTML (simple array)
<table border=1>
<tr>
<td>#</td>
<td>Nom</td>
<tr>
<?php
require 'config.php';
$rows = mysqli_query($conn, "SELECT * FROM client");
$i = 1;
?>
<?php foreach ($rows as $row) : ?>
<tr id_client=<?php echo $row["id_client"]; ?>>
<td><?php echo $row["id_client"]; ?></td>
<td> <?php echo $row["nom_client"]; ?></td>
<td><button type="button" onclick="display_info(this.id_client);">Info client</button></td>
<td><button type="button" onclick="hide_info(<?php echo $row['id_client']; ?>);">Masquer client</button></td>
<?php endforeach; ?>
</div>
</table>
Info array
<table id="info_client" border=1>
<tr>
<td>#</td>
<td>Nom</td>
<td>Prénom</td>
<td>Date de naissance</td>
<td>Adresse</td>
<td>Adresse mail</td>
<td>Téléphone</td>
<td> </td>
</tr>
<?php
require 'config.php';
$rows = mysqli_query($conn, "SELECT * FROM client");
$i = 1;
?>
<tr id_client=<?php echo $row["id_client"]; ?>>
<?php
foreach ($rows as $row) :
?>
<td id="id"><?php echo $row["id_client"]; ?></td>
<td id="nom"><?php echo $row["nom_client"]; ?></td>
<td id="prenom"><?php echo $row["prenom_client"]; ?></td>
<?php echo '<td id="date"' . $class . '>' . $row["client_date_naissance"] . ' </td>'; ?>
<td id="adresse"><?php echo $row["client_adresse"]; ?></td>
<td id="mail"><?php echo $row["client_mail"]; ?></td>
<td id="tph"><?php echo $row["client_tph"]; ?></td>
<td>
<a href="edit_client.php? id_client=<?php echo $row['id_client']; ?>">Modifier</a>
<button type="button" onclick="submitData(<?php echo $row['id_client']; ?>);">Supprimer</button>
</td>
</tr>
My ajax function
function display_info(action) {
$(document).ready(function() {
var data = {
action: action,
id_client: $("#id_client").val(),
nom_client: $("#nom_client").val(),
prenom_client: $("#prenom_client").val(),
client_date_naissance: $("#client_date_naissance").val(),
client_adresse: $("#client_adresse").val(),
client_mail: $("#client_mail").val(),
client_tph: $("#client_tph").val(),
};
$.ajax({
url: 'function.php',
type: 'post',
data: data,
success: function(response) {
$("#" + action).css("display", "block");
location.reload();
}
});
});
}
PHP functions SQL
if(isset($_POST["action"])){
if($_POST["action"] == "insert"){
insert();
}
else if($_POST["action"] == "edit"){
edit();
}
else if($_POST["action"]== "read"){
read();
}
else{
delete();
}
}
function read (){
global $conn;
$id_client = $_POST["action"];
$query = "SELECT * from client WHERE id_client = '$id_client'" ;
mysqli_query($conn, $query);
}
Sorry the lenght.
I know i am doing something wrong but i don’t know…
Thank you guys.