我对 MySQL 语句有一个有效的过滤器,但我不希望页面上一直出现数千条记录。我想最多有30个。有没有一种简单的方法可以做到这一点?还是我在叫错树?!?
如果可能的话,有人可以给我一些帮助吗?
我在查询的开头输入了一个限制语句,当我过滤项目时它失败了。我错过了什么吗?
error_reporting(0);
include("config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GT Entertainment Song Database</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery- ui.css" rel="stylesheet" type="text/css"/>
<style>
BODY, TD {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="search.php">
<label for="Track">CAVS ID</label>
<input name="Track" type="text" id="from" size="10" value="<?php echo $_REQUEST["Track"]; ?>" />
<label>Title or Artist:</label>
<input type="text" name="string" id="string" value="<?php echo stripcslashes($_REQUEST["string"]); ?>" />
<label>Disk</label>
<select name="Disk">
<option value="">--</option>
<?php
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY Disk ORDER BY Disk LIMIT 1,30";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
echo "<option value='".$row["Disk"]."'". ($row["Disk"]==$_REQUEST["Disk"] ? " selected" : "").">".$row["Disk"]."</option>";
}
?>
</select>
<label>Comment</label>
<select name="Comment">
<option value="">--</option>
<?php
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY Comment ORDER BY Comment LIMIT 1,30";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
echo "<option value='".$row["Comment"]."'". ($row["Comment"]==$_REQUEST["Comment"] ? " selected" : "").">".$row["Comment"]."</option>";
}
?>
</select>
<input type="submit" name="button" id="button" value="Filter" />
</label>
<a href="search.php">
reset</a>
</form>
<br /><br />
<table width="700" border="1" cellspacing="0" cellpadding="4">
<tr>
<td width="90" bgcolor="#CCCCCC"><strong>CAVS ID</strong></td>
<td width="95" bgcolor="#CCCCCC"><strong>Track</strong></td>
<td width="159" bgcolor="#CCCCCC"><strong>Artist</strong></td>
<td width="191" bgcolor="#CCCCCC"><strong>Disk</strong></td>
<td width="113" bgcolor="#CCCCCC"><strong>Comment</strong></td>
</tr>
<?php
// Start query
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE 1=1 ";
if ($_REQUEST["string"]!='') {
$sql .= " AND (Title LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR Artist LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%')";
}
if ($_REQUEST["Disk"]!='') {
$sql .= " AND Disk='".mysql_real_escape_string($_REQUEST["Disk"])."'";
}
if ($_REQUEST["Comment"]!='') {
$sql .= " AND Comment='".mysql_real_escape_string($_REQUEST["Comment"])."'";
}
if ($_REQUEST["Track"]!='') {
$sql .= " AND Track='".mysql_real_escape_string($_REQUEST["Track"])."'";
}
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0) {
while ($row = mysql_fetch_assoc($sql_result)) {
?>
<tr>
<td><?php echo $row["Track"]; ?></td>
<td><?php echo $row["Title"]; ?></td>
<td><?php echo $row["Artist"]; ?></td>
<td><?php echo $row["Disk"]; ?></td>
<td><?php echo $row["Comment"]; ?></td>
</tr>
<?php
}
} else {
?>
<tr><td colspan="5">No results found.</td>
<?php
}
?>
</table>
</body>
<a href="http://www.gtentertainment.ca/index.php">Go Back to Home</a>
</html>