Is this possible? I want to output what only inside the isset variable on the same page.. I've had my research by up to this point, I can't find the solution for this kind of problem.
How can I get the data that is inside the isset, it displays data but it gets the whole page as output.
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="jquery.10.2.js"></script>
<script type="text/javascript">
$(function(){
$('.a').click(function(){
var id = $(this).attr('data-id');
alert(id);
$.ajax({
type: 'post',
url: 'index.php',
data:{
connect: 'try',
idx : id
},
success:function(data){
$('span').html(data);
}
});
});
});
</script>
</head>
<body>
<a href="#" data-id="1" class="a">Click 1</a>
<a href="#" data-id="2" class="a">Click 2</a>
<a href="#" data-id="3" class="a">Click 3</a>
<a href="#" data-id="4" class="a">Click 4</a>
<span></span>
<?php
$con = mysqli_connect("localhost", "root", "", "finance");
if(isset($_POST['connect'])){
$x = array();
$data = mysqli_query($con, "SELECT lname FROM tbl_student WHERE id = '$_POST[idx]'");
while ($row = mysqli_fetch_array($data)) {
$x[] = $row;
}
echo 'this is a test echo';
}
?>
</body>
</html>