我做了一个简单的搜索以从数据库中检索客户数据。到目前为止,我只能让它在网页上成功显示当前表格数据,但我无法获得搜索功能来检索特定数据。我有 0 个数据库访问问题。
我已经在护目镜上搜索了几个小时并尝试了许多不同的组合,但我找不到任何关于进行 mysqli 搜索的体面教程。
Cust_no 是主键(varchar), prog_id(integer), balance(varchar)
**Table structure**
Query Output:
> SELECT prog_id, cust_no, balance
FROM `tee`.`teecust`
+ ------------ + ------------ + ------------ +
| prog_id | cust_no | balance |
+ ------------ + ------------ + ------------ +
| 220852 | 1184631 | 0
|
| 220853 | 1184693 | 0
|
| 225726 | 1186292 | 0
|
| 220854 | 1233446 | 0
|
| 220856 | 1233672 | 0
<!DOCTYPE html>
<head>
<title>Search the Database</title>
</head>
<body>
<form action="search.php" method="get" enctype="application/x-www-form-urlencoded" target="_self" id="search">
Search: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
$host="****";
$port="3306";
$socket="";
$user="u*****";
$password="*****";
$dbname="tee";
$mysqli = new mysqli($host, $user, $password, $dbname);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT cust_no FROM teecust LIMIT 20,5";
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_row()) {
printf ("Customer Number:%s Billing ID:%s Balance due:%s\n", $row["cust_no"], $row["prog_id"], $row["balance"]);
}
/* free result set */
$result->close();
}
/* close connection */
$mysqli->close();
?>
</body>
</html>