gpt4 book ai didi

当我搜索时,php 和 mysql 数据库不工作

转载 作者:行者123 更新时间:2023-11-29 12:09:22 25 4
gpt4 key购买 nike

我的 php 代码有问题。我用

创建了一个数据库
    id int(11) NOT NULL AUTO_INCREMENT,
isbn varchar2 NOT NULL,
title varchar2 NOT NULL,
author varchar2 NOT NULL,
publisher varchar2 NOT NULL,
year date NOT NULL,
PRIMARY KEY (`id`)

我在 mysql 数据库中有一个图书列表:

ISBN: 0763754891
Title: Web Development with JavaScript and AJAX Illumination
Author: Richard Allen, Kai Qian , LiXin Tao, Xiang Fu
Publisher: Jones& Bartlett
Date: 2009

ISBN: 9780763754204
Title: Software Architecture and Design Illuminated
Author: Kai Qian, Xiang Fu, LiXin Tao, Jorge Diaz-Herrera,Chong-wei Xu
Publisher: Jones & Bartlett
Date: 2009

ISBN: 0763734233
Title: Java Web Development Illuminated
Author: Kai Qian, Richard Allen, Mia Gan,Bob Brown
Publisher: Jones & Bartlett
Date: 2007

ISBN: 0471644463
Title: Component Oriented Programming
Author: Andy Wang, Kai Qian
Publisher: Wiley
Date: 2005

ISBN: 9781441906052
Title: Embedded Software Development with C
Author: Kai Qian, David den Haring, Li Cao
Publisher: Springer
Date: 2010

这是我的 html 和 php 代码

<html>
<head>
<title>Book Store</title>
</head>
<body>
<h3> Book Store </h3>

<p> *****Welcome to use book store system***** <p>
<form action = "" method = "GET">
Find entries that are:<br/>
Author: <input type = "text" name = "author" />
Title : <input type = "text" name = "title" />
<p></p>
Year :
<p></p>
<select name = "select">
<option value=""/></option>
<option value=2005/>2005</option>
<option value=2007/>2007</option>
<option value=2009/>2009</option>
<option value=2010/>2010</option>
</select>
<p></p>
<input type = "submit" name="submit" value="search"/>
</form>
</body>
</html>



<?php
session_start();

if($_GET){

$author = $_GET['author'];
$title = $_GET['title'];
$select = $_GET['select'];

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());

if($connect)
{
mysql_select_db("mysql", $connect);

$query = "SELECT * FROM bookstore WHERE author='" . $author . "' or Title='" . $title . "' ";

$query2 = "SELECT * FROM bookstore WHERE Year = '" . $select ."' ";

$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());

while($row = mysql_fetch_array($result)){

echo $row['ISBN'] . "<br/>" . $row['Title'] . "<br/>" . $row['Author'] . "<br/>" . $row['Publisher'] . "<br/>" . $row['Year'] . "<br/>";

}
while($row2 = mysql_fetch_array($result2)){
echo $row2['ISBN'] . "<br/>" . $row2['Title'] . "<br/>" . $row2['Author'] . "<br/>" . $row2['Publisher'] . "<br/>" . $row2['Year'] . " <br/>";
}
} else {
die(mysql_error());
}
mysql_free_result($result);
mysql_close();
}

?>

我应该能够搜索“Qian”作为作者和“Java”作为标题,但只有当我在搜索区域中写下整个书名或所有作者姓名时,它才有效。我该如何解决这个问题?

最佳答案

= 进行完全匹配。您需要使用LIKE来搜索模式。

$query = "SELECT * 
FROM bookstore
WHERE author LIKE '%" . $author . "%'
OR Title LIKE '%" . $title . "%' ";

关于当我搜索时,php 和 mysql 数据库不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30948876/

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