0

I am trying to pull data from MySQL and this supposed to show complete data but this is showing only one row. This is supposed to show all rows of users. I don’t know what I did wrong:

Here is the code:

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;
}
Giacomo1968
25.4k11 gold badges78 silver badges106 bronze badges
asked May 24, 2014 at 17:00

1 Answer 1

2

On this line you have if:

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

If you use if that would only go to the first value since if simply tests a condition once. Instead try while like this:

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

As explained in the PHP manual entry for while:

The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE.

answered May 24, 2014 at 17:03
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.