$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);
您需要
为每一行调用mysqli_fetch_array()
。
while ($pKeyArray = mysqli_fetch_array($PKeyDetails)) {
print_r($pKeyArray);
}
使用 mysqli_fetch_all
:
$array = mysqli_fetch_all( $PKeyDetails);
您必须使用循环,因为 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
while($pKeyArray = mysqli_fetch_array($PKeyDetails)) {
print_r($pKeyArray);
}