1

$pKeyArray 只打印满足 WHERE 子句的数据库中的第一行,为什么不显示满足 WHERE 子句的所有行,我不想把它放在任何循环中,我只需要一个 P_Key 的数组所有行。

$getPKey = "SELECT P_Key FROM likersTable WHERE executed=0";
$PKeyDetails = mysqli_query($dbConnect,$getPKey)
                or die('Some error in post id');
$pKeyArray = mysqli_fetch_array($PKeyDetails);
print_r($pKeyArray);
4

4 回答 4

2

您需要mysqli_fetch_array()为每一行调用。

while ($pKeyArray = mysqli_fetch_array($PKeyDetails)) {
    print_r($pKeyArray);
}
于 2012-05-08T17:52:42.643 回答
1

使用mysqli_fetch_all

$array = mysqli_fetch_all( $PKeyDetails);
于 2012-05-08T17:52:42.053 回答
0

您必须使用循环,因为mysqli_fetch_*()函数每次调用仅返回一行。

使用此代码:

$getPKey = "SELECT P_Key FROM likersTable WHERE executed=0";
$PKeyDetails = mysqli_query($dbConnect,$getPKey)
                or die('Some error in post id');

while ($row=mysqli_fetch_array($PKeyDetails))
{
  // Do something with $row
}

或使用mysqli_fetch_all()

$result = mysqli_fetch_all($PKeyDetails, MYSQLI_ASSOC); // or use MYSQLI_NUM
于 2012-05-08T17:53:01.333 回答
0
while($pKeyArray = mysqli_fetch_array($PKeyDetails)) {
    print_r($pKeyArray);
}
于 2012-05-08T17:53:01.390 回答