-1

these lines of code :

$sql ="SELECT * FROM parcours";
$r = mysqli_query($con,$sql);
$result = array();

while($res = mysqli_fetch_array($r)){

 $result[] = $res;
}
echo json_encode(array("result"=>$result));

returns me only the first row of my DB request.

How can I get all of it ?

6
  • Nothing looks obviously wrong with this. You're sure parcours has more than 1 row in it? after your while loop var_dump($result) has more than 1 item? Commented Apr 9, 2017 at 18:09
  • Yes it has .... Commented Apr 9, 2017 at 18:10
  • var_dump($result) has all your rows returned? Commented Apr 9, 2017 at 18:13
  • var_dump($result) returned me 2 rows (which is the number of rows) Commented Apr 9, 2017 at 18:15
  • Can you copy the output of your echo into your question. It doesn't look like anything is wrong so far. Commented Apr 9, 2017 at 18:16

1 Answer 1

0

I think you need to use mysqli_fetch_assoc :

while($res = mysqli_fetch_assoc($r)){

 $result[] = $res;
}

and then :

echo json_encode(array($result));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.