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

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

我知道这在while循环中很有用,您可以在其中循环遍历结果。

但是我需要能够获取满足此条件的特定行。此伪代码之后的内容:
$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)

关于php - Mysqli获取数组第n行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12126333/

10-10 08:43