function CHECKPENDINGORDERS($con, $oc, $pos){
if(is_resource($con)){
$sql = "SELECT * FROM eats_orders WHERE school_code = '$oc' AND order_status = '$pos'";
$sqlresult = mysql_query($sql);
#$pendingorderrow = mysql_fetch_array($sqlresult);
while($row = mysql_fetch_assoc($sqlresult)){
$a[] = $row;
return $a;
}
}
}
$checkpendingorders = CHECKPENDINGORDERS(MYSQL_LINK, $ordercode, $pendingorderstatus);
print_r($checkpendingorders);
我有一个上面的函数来检索数据库记录,并通过调用该函数将其打印出来。但它只打印了一个记录,但我有多个记录具有相同的ordercode和pendingorderstatus。
最佳答案
您需要在最后返回$a
<?php
function CHECKPENDINGORDERS($con, $oc, $pos){
if(is_resource($con)){
$sql = "SELECT * FROM eats_orders WHERE school_code = '$oc' AND order_status = '$pos'";
$sqlresult = mysql_query($sql);
#$pendingorderrow = mysql_fetch_array($sqlresult);
while($row = mysql_fetch_assoc($sqlresult)){
$a[] = $row;
//return $a; //<---- Not here
}
}
return $a; //<----- Here
}
那是因为。。。您得到的是一行,因为您在第一次迭代中返回了
$a
。关于php - MYSQL打印数据库记录数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21870231/