gpt4 book ai didi

PHP 和 MySQL 限制无法正常工作。

转载 作者:行者123 更新时间:2023-11-29 04:47:10 25 4
gpt4 key购买 nike

我有一个针对 MySQL 语句的有效过滤器,但我不希望所有数千条记录一直出现在页面上。我想最多有 30 个。有没有一种简单的方法可以做到这一点?还是我找错了树?!?

如果可能有人可以给我一些帮助吗?

我在查询的开头放入了一个 Limit 语句,当我过滤项目时它失败了。我错过了什么吗?

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>

最佳答案

你需要输入LIMIT子句在您的查询的最后,

.............
if ($_REQUEST["Track"]!='') {
$sql .= " AND Track='".mysql_real_escape_string($_REQUEST["Track"])."'";
}
$sql .= " LIMIT 30";

注意: Please, don't use mysql_* functions in new code .它们不再维护 and are officially deprecated .查看red box ?了解 prepared statements相反,并使用 PDO , 或 MySQLi - this article将帮助您决定选择哪个。如果选择 PDO,here is a good tutorial .

关于PHP 和 MySQL 限制无法正常工作。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17334682/

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