2
$responses = array();
while ($row = mysql_fetch_array($result)) {
    $response = array(
    'name' => $row['name']
    );

    $row;

    $responses['name5'] = $response;
}
echo json_encode($responses);

I'm currently only getting 1 rows from this statement I know for a fact their are more.

0

5 Answers 5

7

On each iteration of your while loop, you are overwriting the same array key $responses['name5'], so in the end you'll only have one value in the $responses array.

Instead, you might want something like this to append to the end of the array:

$responses[] = $response;
Sign up to request clarification or add additional context in comments.

Comments

1

you are overwriting the $response variable that's why, array_push instead

Comments

1

$responses['name5'] = $response;

You will get only last row because you replace your data each cycle step. Try this: $responses['name5'][] = $response;

Comments

0

Because you're resetting the $response array to a single array in the loop. You want to add to the array.

$responses = array();
while ($row = mysql_fetch_array($result)) {
    array_push($response, array(
    'name' => $row['name']
    ));

    $row;

    $responses['name5'] = $response;
}
echo json_encode($responses);

Comments

0

do

$responses[] = array('name5' => $response);

Comments

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.