0

I am fetching multiple records from database and try to store into json array, but the only last record will get stored into array, can any one have any idea about this? How to store multiple data into an json array. and I have to display this array on the full-calendar.

here is my code:

foreach($result as $row){
    $records[$i][0]=substr($row['date'], 0, 10);
    $records[$i][1]=$row['in_time'];
    $records[$i][2]=$row['out_time'];
    $records[$i][3]=$row['attendance']; 

    $e['date']=$records[$i][0];
    $e['start']=$records[$i][1];
    $e['end']=$records[$i][2];
    $e['attendance']=$records[$i][3];

    $i++;

}
echo json_encode($e);   

how to create multiple records json data ?

1
  • 4
    You're overwriting $e every loop. What are you expecting to happen? Commented Feb 14, 2017 at 4:34

1 Answer 1

1

You are overwriting $e again and again.That's the problem. So do like below:-

 $e[$i]['date']=$records[$i][0];
 $e[$i]['start']=$records[$i][1];
 $e[$i]['end']=$records[$i][2];
 $e[$i]['attendance']=$records[$i][3];
Sign up to request clarification or add additional context in comments.

1 Comment

@MangeshKolape glad to help you.

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.