1

When I run the following query in phpmyadmin:

SELECT firstName, lastName, credits FROM volunteers ORDER BY credits, firstName ASC

I get 9 rows as the result. But when I run the following code in php, the $storing_data variable stores the array value of only one row.

$query_for_credits_table=mysqli_query($conn, "SELECT firstName, lastName, credits FROM volunteers ORDER BY credits, firstName ASC;");
$storing_data=mysqli_fetch_assoc($query_for_credits_table);

What will I have to do to store the complete information in the variable??

2
  • you get a table back, and you want to store it in a variable, do you mean an array or json? Commented Apr 19, 2020 at 11:03
  • I want to store the data as an array Commented Apr 19, 2020 at 11:05

1 Answer 1

1

You have to loop through the results and build then the array

$query_for_credits_table=mysqli_query($conn, "SELECT firstName, lastName, credits FROM volunteers ORDER BY credits, firstName ASC;");

if( $query_for_credits_table){
    while ($row = mysqli_fetch_assoc($query_for_credits_table)) {
        $user = array(
            'firstName' => $row['firstName'],
            'lastName' => $row['lastName'],
            'credits ' => $row['credits ']
        );
    }
    $storing_data[] = $user;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Or just use mysqli_fetch_all().

Your Answer

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.