1

脚本功能:允许用户搜索艺术家姓名或歌曲名称

对其他用户的好处:可以轻松修改脚本,以供其他 stackoverflow 用户工作和搜索他们的网站 - 只需将查询更改为您的数据库结构。

$query_Recordset1 = sprintf("SELECT * FROM lyrics WHERE title LIKE '%%%s%%' ORDER BY title ASC", $colname_Recordset1);

ISSUE with script:它适用于歌曲标题,但我不明白如何在不使用更改搜索的下拉菜单的情况下同时搜索艺术家姓名和歌曲标题。没有结果时也会返回错误

艺术家示例 (Rihanna - id : 16689) (title : Unfaithful - id : 228106) http://www.thelyricsfinder.com/song.php?sid=228106&aid=16689

Search.php 的实时/工作示例

  • 没有结果时收到错误输出(下)

..

错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '' 附近使用正确的语法

$maxRows_Recordset1 = 100;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "-1";
if (isset($_POST['term'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['term'] : addslashes($_POST['term']);
}
mysql_select_db($database_main, $main);
$query_Recordset1 = sprintf("SELECT * FROM lyrics WHERE title LIKE '%%%s%%' ORDER BY title ASC", $colname_Recordset1);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $main) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

目标:为了使脚本从传递给 $_POST['term'] 的单个搜索中搜索两个表/行,但 KICKER 将结果返回到两个单独的变量中以单独显示。

  1. 艺术家/艺术家
  2. 歌词/标题

感谢您帮助我找到如何做到这一点。回到书本上,试图得到答案。

2012 年 11 月 2 日添加(我知道我可以通过在下面添加未找到的处理结果来帮助解决部分问题,感谢以下人员的帮助,现在我需要学习如何同时进行这两个查询)

4

2 回答 2

1

我认为你必须有一个单独的过程来进行空结果查询。由于问题不是“超过两个词”,而是搜索结果为空时。尝试这样的事情

$Recordset1 = mysql_query($query_limit_Recordset1, $main) or die(mysql_error());
$num_rows = mysql_num_rows($Recordset1 );
if($num_rows == 0){
   //error message
}
else{
   //process here
}
于 2012-10-23T03:54:09.877 回答
1

我刚刚搜索Fool on the hill了两个以上的单词,并且有效。然后Fill on the bill给出了你所说的错误。

ERROR : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

这只是意味着当搜索词与数据库中没有记录匹配时,您需要处理返回的空行情况。

于 2012-10-23T03:58:57.243 回答