gpt4 book ai didi

php - 选择语法未正确显示(不确定是否重复)

转载 作者:搜寻专家 更新时间:2023-10-30 20:54:24 25 4
gpt4 key购买 nike

我目前正在研究生院做一个项目。我正在构建一个可写和可搜索的数据库。我已经完成了可写方面的工作,但是我在搜索功能方面遇到了问题。问题是我无法搜索和显示数据库中的单个行,只能搜索和显示整个数据库,老实说,如果数据库有 20k 个项目而你只需要 20 个,则功能不是很好。

我正在完整复制下面的代码。

        <?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_NOTICE);

// --------------------------------------------------------
/* THIS DEMO FILE ACCEPTS DATA FROM A WEB FORM
AND SAVES THE DATA TO A FLAT FILE AND THEN TO A DATABASE.
AS A CHECK WE READ THE DATA BACK FROM THE TABLE AND FROM
THE FILE.
Created by: PATRICK DUFF, based on example written by G. Benoit, on 2/28/15
Modified on: 3/1/15, 3/5/15/ 3/13/15
Contact: xxxxxxx
*/
// --------------------------------------------------------
/* GETTING READY FOR THE DATA */
/* the file to hold the data */
$filename = "testData.txt";
$status = "";
/* name of the database, table, username, password, table */
$hostname = "xxxxxxx"; // change this vars for your own db
$username = "xxxxx"; // whatever your student email user name is
$password = "xxxxx"; // your usual password
$dbname = "xxxxxx"; // this database name is assigned for you by the Lab Staff Lab Staff
$table = "xxxxxx"; // once you’re using your DB, you can create your own tables

//getting data from webfrom

$isbn = $_POST["isbn"];
$lname = $_POST["lname"];
$fname = $_POST["fname"];
$title = $_POST["title"];
$publisher = $_POST["publisher"];
$genre = $_POST["genre"];
$con = mysqli_connect("$hostname", "$username", "$password", "$dbname");
$isbn = $_POST["isbn"];
$lname = $_POST["lname"];
$fname = $_POST["fname"];
$title = $_POST["title"];
$publisher = $_POST["publisher"];
$genre = $_POST["genre"];
$con = mysqli_connect("$hostname", "$username", "$password", "$dbname");

//retrieving data from flat form & database.

echo "<!DOCTYPE html><html><head> <title> Record Search </title></head>";
echo "<body> Here is the data: The file contents of 'testData.txt so far is/are: ";
echo file_get_contents($filename);
echo "<hr /> End of reading file. Attempting to read database <hr />";
//creating searchability
$sql= "SELECT * FROM myLibrary WHERE isbn LIKE '%" .$isbn." %' OR fname LIKE '%" .$fname." %' OR lname LIKE'%" .$lname." %' OR title LIKE '%" .$title." %' OR publisher LIKE '%" .$publisher." %' OR genre LIKE'%" .$genre."%' ORDER BY lname" or
die(mysql_error());
$result = mysqli_query($con, $sql);

//displays result in table
if ($result->num_rows > 0) {
echo "<table id='myLibrary'><tr><th><u>ISBN</u></th><th> <u>First Name</u></th><th><u> Last Name </u></th><th><u> Title</u> </th><th><u>Publisher</u></th> <th><u>Genre</u></th></tr>";
// output data of each row
while($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $row["isbn"]."</td><td>". $row["fname"]."</td><td>" . $row["lname"]. "</td><td>" .$row["title"]. "</td><td>" .$row["publisher"]. "</td><td>".$row["genre"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}

echo "End of Results";

出于某种原因,当我注释掉表格时,表格中的任何内容都没有显示。

我希望这已经够清楚了,这是我第一次在这里发帖。

最佳答案

您只需要限制查询以避免返回所有结果。

$limit = 10;
$sql= "SELECT * FROM myLibrary WHERE isbn LIKE '%" .$isbn." %' OR fname LIKE '%" .$fname." %' OR lname LIKE'%" .$lname." %' OR title LIKE '%" .$title." %' OR publisher LIKE '%" .$publisher." %' OR genre LIKE'%" .$genre."%' ORDER BY lname LIMIT " .$limit . ""

关于php - 选择语法未正确显示(不确定是否重复),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29166282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com