php MySQL - 无法跳转到 MySQL 结果索引的第 0 行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8342054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:29:14  来源:igfitidea点击:

MySQL- Unable to jump to row 0 on MySQL result index

phpmysqldatabase

提问by Zabs

I have got an old site that has recently been displaying an error which is weird as its been untouched for some time. I get the following:

我有一个旧网站,它最近一直显示一个错误,这很奇怪,因为它有一段时间没有受到影响。我得到以下信息:

Unable to jump to row 0 on MySQL result index 8

What is the cause of this and how should I fix it?

这是什么原因,我该如何解决?

It is a PHP/MySQL site.

它是一个 PHP/MySQL 站点。

回答by nickb

If I remember correctly, this error typically stems from a code segment like the following:

如果我没记错的话,这个错误通常源于如下代码段:

// You probably have some code similar to this
$var = mysql_result( $result, 0, 'column_name');

Where either the query fails or the column doesn't exist. Check that $resultis a valid MySQL resource to make sure that the SQL is valid, then make sure you're actually getting results from the database before trying to call mysql_result.

查询失败或列不存在的地方。检查这$result是一个有效的 MySQL 资源以确保 SQL 有效,然后确保在尝试调用mysql_result.

Or, better yet, using mysql_fetch_arrayinstead of manually fetching every column value (if you have multiple columns returned from the query).

或者,更好的是,使用mysql_fetch_array而不是手动获取每个列值(如果您从查询返回了多个列)。

回答by Minras

Try analysing the result before fetching it. If result is empty, skip fetching.

在获取结果之前尝试分析结果。如果结果为空,则跳过获取。

$result = mysql_query("SELECT * FROM table1");
if (!$result || !mysql_num_rows($result)) {
    die('Empty set.');
}
while ($row = mysql_fetch_array($result)) {
    // Your code here
}