此代码有问题..个人资料搜索有效 正确地只是“查看个人资料”按钮不起作用,我希望我 可以显示每个成员的按钮并进入特定页面, 你可以帮帮我吗?而且,如何不单击任何内容就无法显示整个查询?非常感谢,对不起,我的英语水平
index.php
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test search</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
</script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
rel="stylesheet" />
</head>
<body>
<div class="container">
<br />
<h2 align="center"> Ajax Live Data Search</h2>
<br />
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Search</span>
<input type="text" name="search_text" id="search_text"
placeholder="Search by Customer Details" class="form-control" />
</div>
</div>
<br />
<div id="result"></div>
</div>
</html>
<script>
$(document).ready(function() {
load_data();
function load_data(query) {
$.ajax({
url: "fetch.php",
method: "POST",
data: {
query: query
},
success: function(data) {
$('#result').html(data);
}
});
}
$('#search_text').keyup(function() {
var search = $(this).val();
if (search != '') {
load_data(search);
} else {
load_data();
}
});
});
fetch.php
<?php
$connect = mysqli_connect("localhost", "xxx", "xxx",
"testing");
$output = '';
if (isset($_POST["query"])) {
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM tbl_customer
WHERE CustomerName LIKE '%" . $search . "%'
OR Address LIKE '%" . $search . "%'
OR City LIKE '%" . $search . "%'
OR PostalCode LIKE '%" . $search . "%'
OR Country LIKE '%" . $search . "%'
";
} else {
$query = "
SELECT * FROM tbl_customer ORDER BY CustomerID
";
}
$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
$output .= '
<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>Customer Name</th>
<th>Address</th>
<th>City</th>
<th>Postal Code</th>
<th>Country</th>
<th> <a class="viewProfile" href="index.php?id=' . ['CustomerID'] . '">
<btn btn-primary>View Profile</btn btn-primary></a><th>
</tr>
';
while ($row = mysqli_fetch_array($result)) {
$output .= '
<tr>
<td>' . $row["CustomerName"] . '</td>
<td>' . $row["Address"] . '</td>
<td>' . $row["City"] . '</td>
<td>' . $row["PostalCode"] . '</td>
<td>' . $row["Country"] . '</td>
<td>' . $row["CustomerID"] . '</td>
</tr>
';
}
echo $output;
} else {
echo 'Data Not Found';
}