im using datatables, and this is my some of my code for fetching the data for datatables, this works fine now what i want is to load dynamic content on when someone hover or click the anchor tag... this the image datatables data
foreach($result as $row)
{
$sub_array = array();
$sub_array[] = '<a href="#" class="hover" id="'.$row['id'].'">'.clean($row["f_name"])." ".clean($row["m_name"])." ".clean($row["l_name"]).'</a>';
$sub_array[] = strtoupper($row["sex"]);
$sub_array[] = $row["birthdate"];
$sub_array[] = $row['age'];
$data[] = $sub_array;
}
this is what i have tried, still the bootstrap popover not working
$('.hover').popover({
title:fetchData,
html:true,
placement:'right'
});
function fetchData(){
var fetch_data='';
var element = $(this);
var id = element.attr("id");
$.ajax({
url:"../controller/fetch_single.php",
method:"POST",
async:false,
data:{id:id},
success:function(data){
fetch_data = data;
alert(data);
}
});
return fetch_data;
}
this is the code that i used for my ajax
//fetch_single.php
if(isset($_POST["id"]))
{
$output = '';
$statement = $connection->prepare(
"SELECT id, sex, f_name, m_name, l_name, birthdate,image_name,house_num,street TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) as age from rec_personal WHERE id='".$_POST['id']."'"
);
$statement->execute();
$result = $statement->fetchAll();
foreach ($result as $row) {
$output = '
<p><img src="../upload/'.$row["image_name"].'" class="img-responsive img-thumbnail" /></p>
<p><label>Name : '.$row['f_name'].'</label></p>
<p><label>Address : </label><br />'.$row['house_num'].'</p>
<p><label>Gender : </label>'.$row['sex'].'</p>
<p><label>Age : </label>'.$row['age'].' Years</p>
';
}
echo $output;
}
EDIT this is my reference for the code http://www.webslesson.info/2016/11/php-ajax-jquery-load-dynamic-content-in-bootstrap-popover.html