<html>
<head>
<script type="text/javascript" src="jquery-3.0.0.min.js"></script>
</head>
<body>
<form method="POST">
<input type="text" class="form-control" placeholder="Search" name ="searchterm">
<a href="#" id="button"><button type="submit" id="submit">click me</button></a>
</form>
<script>
$(document).ready(function(){
$("#button").click(function(){
$.get("search.php");
return false;
});
});
</script>
</body>
</html>
<?php
mysql_connect("localhost","root","");
mysql_select_db("testdb");
$search = mysql_real_escape_string(trim($_POST['searchterm']));
$find_categories = mysql_query("SELECT `person3`,`person4` FROM `dbtable` WHERE `person1` LIKE'%$search%'");
$data = array();
while($row = mysql_fetch_assoc($find_categories))
{
$data[]=$row;
}
echo json_encode($data);
?>
我在从数据库中获取数据并显示数据时遇到问题。我怎么能这样做,有什么方法可以让我在弹出窗口中显示它?
答案 0 :(得分:0)
this is the output after removing the jquery and writing php in the same file
<!doctype html>
<html>
<head>
<script type="text/javascript" src="jquery-3.0.0.min.js"></script>
</head>
<body>
<form method="POST">
<input type="text" class="form-control" placeholder="Search" name="searchterm">
<a href="#" id="popup"><button type="submit" id="submit">click me</button> </a>
<?php
mysql_connect("localhost","root" ,"");
mysql_select_db("testdb");
$search = mysql_real_escape_string(trim($_POST['searchterm']));
$find_categories = mysql_query("SELECT `person3`,`person4` FROM `dbtable` WHERE `person1` LIKE'%$search%'");
$data = array();
while($row = mysql_fetch_assoc($find_categories))
{
$data[]=$row;
}
echo json_encode($data);
?>
</form>
</body>
</html>