Mysqli获取数组第n行 [英] Mysqli fetch array nth row

查看:91
本文介绍了Mysqli获取数组第n行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可读取一行:

I have the following code that fetches a single row:

$query = "SELECT *
          FROM translations
          WHERE iddoc = '$id'
          AND submitted = 1;";
$result = mysqli_query($query);
$row = mysqli_fetch_array($result);

我知道这在while循环中很有用,您可以在其中循环浏览结果.

I know this is useful in a while loop, where you can just loop through the results.

但是我需要能够获取满足此条件的特定行.此伪代码之后的内容:

But I need to be able to grab specific rows that meet this condition. Something following this pseudo code:

$query = "SELECT *
          FROM translations
          WHERE iddoc = '$id'
          AND submitted = 1;";
$result = mysqli_query($query);
$arrayofrows = mysqli_fetch_arrayofrows($result);
$arrayofrows[0] //(to get the first row)
$arrayofrows[1] //(2nd row)

以此类推...

我该怎么做?

推荐答案

您可以尝试这样的事情

$arrayofrows = array();
while($row = mysqli_fetch_array($result))
{
   $arrayofrows = $row;
}

您现在可以拥有

$arrayofrows[0] //(to get the first row)
$arrayofrows[1] //(2nd row)

这篇关于Mysqli获取数组第n行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆