【问题标题】:Unable to jump to row 0无法跳转到第 0 行
【发布时间】:2013-09-08 15:58:53
【问题描述】:

我有一个奇怪的问题,在重命名(并在查询中更新)MySQL 表后,当我执行搜索时收到以下警告:

警告:mysql_result() [function.mysql-result]:无法跳转到第 94 行 D:\dev\search.php 中 MySQL 结果索引 8 的第 0 行

这是我的代码:

$query = "SELECT * FROM admin WHERE ((`status_desc` LIKE '%".$search."%') OR ('%".$search."%')) LIMIT 100";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_numrows($result);

第 94 行是$status_id:

<?php
$i=0;
while ($i < $num)
{
    $status_id = mysql_result($result,$i,"status_id");
    $status_des = mysql_result($result,$i,"status_desc");
?>
<tr>
    <td><a href="config_status_edit.php?status_id=<?php echo $status_id; ?>"><?php echo $status_id; ?></a></td>
    <td><?php echo $status_desc; ?></td>
</tr>
<?php
    $i++;
}
?>

怎么了? (我已经计划更新到 PDO 但现在我需要使用 mysql_query)

【问题讨论】:

  • 这是mysql_num_rows 不是mysql_numrows。现在试试$num = mysql_num_rows($result);
  • 您是否有任何特殊原因要以这样的方式阅读查询而不是常规方式?
  • 对不起,输入错误,但没有解决问题:-(
  • @user2307958 所以这不是你的实际代码。 line 94 是什么?
  • @Prix。不,但是脚本最初是这样开发的……

标签: php mysql


【解决方案1】:

使用 mysql_fetch_* 函数代替 mysql_result

$query = "SELECT * FROM admin WHERE ((`status_desc` LIKE '%".$search."%') OR ('%".$search."%')) LIMIT 100";
$result = mysql_query($query) or die(mysql_error());

while ( ($row=mysql_fetch_assoc($result)) ) {
   $status_id = $row["status_id"];
   $status_des = $row["status_desc"];
?>
   <tr>
      <td>
         <a href="config_status_edit.php?status_id=<?php echo $status_id; ?>">
            <?php echo $status_id; ?>
         </a>
      </td>
      <td><?php echo $status_desc; ?></td>
   </tr>
<?php
}

它将循环直到它没有更多的行来获取,不需要设置/检查计数器等。

【讨论】:

  • 嗯,这并没有回答为什么他的方法不起作用的问题,但实际上这将是一种更好的阅读方式。
【解决方案2】:

验证$num

if ($num > 0) {
    echo "rows found";
    } else {
    echo "none found";
}

 WHERE (`status_desc` LIKE '%".$search."%' OR `status_desc`LIKE '%".$othersearch."%')
 WHERE (`status_desc` LIKE '%".$search."%' OR `other_column`LIKE '%".$search."%')

在 sql 客户端中运行您的查询,我怀疑这是问题所在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 2017-02-13
    • 2017-05-22
    相关资源
    最近更新 更多