我的代码有什么问题吗?具体错误信息为:
Error querying database 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 5
我的代码是:
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$query = mysql_query("
SELECT timein, timeout
FROM studentInfo
WHERE name = '$name'
ORDER BY time DESC
LIMIT *
")
or die("Error querying database ".mysql_error());
while($minutes = mysql_fetch_array($query)){
echo "timein: ".$minutes['timein']."<br />";
echo "timeout: ".$minutes['timeout']."<br />";
}
}
最佳答案
这是错误的:
LIMIT *
在Limit
之后输入一些整数而不是*
通配符。
根据 documentation :
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).
有两个参数,第一个参数指定要返回的第一行的偏移量,第二个参数指定要返回的最大行数。初始行的偏移量为 0(不是 1):
SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
要检索从某个偏移量到结果集末尾的所有行,可以使用较大的数字作为第二个参数。此语句检索从第 96 行到最后一行的所有行:
SELECT * FROM tbl LIMIT 95,18446744073709551615;
通过一个参数,该值指定从结果集开头返回的行数:
SELECT * FROM tbl LIMIT 5; # Retrieve first 5 rows
换句话说,LIMIT row_count 相当于 LIMIT 0, row_count。
关于php - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 5 行 '*' 附近使用的正确语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384728/