2014-05-24 65 views
0

我想從MySQL中提取數據,這應該顯示完整的數據,但這隻顯示一行。這應該顯示所有用戶行。我不知道我做錯了什麼:在這個PHP函數中沒有像預期的那樣工作

下面是代碼:

function getCashoutRequests($uid, $limit) { 
if (!empty($limit)) { 
    $query = mysql_query('' . 'SELECT * FROM cashouts WHERE uid = ' . $uid . ' ORDER BY id DESC LIMIT ' . $limit); 
} 
else { 
    $query = mysql_query('' . 'SELECT * FROM cashouts WHERE uid = ' . $uid . ' ORDER BY id DESC'); 
} 


if (mysql_num_rows($query)) { 

    if ($row = mysql_fetch_object($query)) { 
     $row->id; 
     $amount = $row->amount; 
     $status = $row->status; 
     $client_notes = nl2br($row->user_notes); 
     $admin_notes = nl2br($row->admin_notes); 
     $request_date = $row->request_date; 
     $payment_date = $row->payment_date; 
     $fee = $row->fee; 
     $priority = $hid = $row->priority; 
     $method = $row->method; 

     if ($payment_date != '0000-00-00 00:00:00') { 
      $payment_date = date('d M, Y', strtotime($payment_date)); 
     } 

     $request_date = date('d M, Y', strtotime($request_date)); 

     $payHistory []= array('id' => $hid, 'cash' => $amount, 'status' => $status, 'method' => $method, 'client_notes' => $client_notes, 'admin_notes' => $admin_notes, 'date' => $request_date, 'payment_date' => $payment_date, 'fee' => $fee, 'priority' => $priority); 
    } 

    return $payHistory; 
} 

return false; 
} 

回答

2

在此行中你有if

if ($row = mysql_fetch_object($query)) { 

如果使用if將只能去自if以來的第一個值只是簡單地測試一次。相反,嘗試while這樣的:

while ($row = mysql_fetch_object($query)) { 

由於PHP手冊條目while解釋說:

while語句的意思很簡單。它告訴PHP重複執行 嵌套語句,只要while表達式 的計算結果爲TRUE。

相關問題