get dynamic content by name in PHP [duplicate] - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, April 18, 2023

get dynamic content by name in PHP [duplicate]

am looking for a way to output the dynamic content data by first_name (fn)

this index indeximg

the results are displayed screenshot 1

i want the result to be displayed like this screenshot 2

this html

<table class="my-2" border='0' width='100%'>
<tr style='color:#fff;' >
<td>First Name</td>
<td>Last Name</td>
<td>Last Update</td>
<td>Devisi</td>
<td>View</td>
</tr>
<?php 
$query = "SELECT d1.id,last_name,first_name FROM customers d1
INNER JOIN
(SELECT MAX(id) AS id FROM customers GROUP By first_name ) AS P ON (d1.ID=P.ID) ORDER BY id DESC";
$result = mysqli_query($con,$query);
while($row =mysqli_fetch_assoc($result))
{   
$id=$row['id'];
$fn=$row['first_name'];
$ln=$row['last_name'];
echo "<tr style='color:#fff;'>";
echo "<td border='0' width='20%'>".$fn;"</td>";
echo "<td border='0' width='20%'>".$ln;"</td>";
echo "<td border='0' width='20%'></td>";
echo "<td border='0' width='20%'></td>";
echo "<td border='0' width='20%'><button data-id='".$fn."' class='btn btn-warning my-2 nameinfo'>Data</button></td>";
echo "</tr>";
}
?>
</table>

Javascript

 $(document).ready(function(){
    $('.nameinfo').click(function(){
         var fn = $(this).data('fn');
         $.ajax({
               url: 'ajx.php',
               type: 'post',
               data: {fn: fn},
               success: function(response){
                   $('.modal-body').html(response);
                    $('#empModal').modal('show'); 
               },
         });
    });
});

this is my code of ajx.php

<?php
include "db.php";

$fn = 0;
if(isset($_POST['fn'])){
    $fn = mysqli_real_escape_string($con,$_POST['fn']);
}

$sql = "select first_name, last_name from customers where first_name=".$fn;
$result = mysqli_query($con,$sql);


while( $row = mysqli_fetch_array($result) ){
    ?>
    <table border='0' width='100%'>
    <tr>
    <td width="50%"><?php echo $row['first_name'];?></td>
    <td><?php echo $row['last_name'];?></td>
    </tr>
    </table>
    <?php
}

?>

pop up name on dynamic content by name



source https://stackoverflow.com/questions/76038552/get-dynamic-content-by-name-in-php

No comments:

Post a Comment