Wednesday 28 November 2018

PHP variable does not update inside of the Javascript while loop

I'm very new to web programming so I will try to explain my issue here! So basically I tried to get all the data from my query in PHP and push everything into an array in Javascript. The code below works for the first iteration, but it seems like after the first one, the rest just gets duplicated (it seems like the $i variable does not update?)
Can someone explain to me why is that and how should I fix it? Thanks!




...
$result = mysqli_query($con, $query);
$num_rows = mysqli_num_rows($result);
$i = 0;
$history_array = array();

if($num_rows > 0){
while($row = mysqli_fetch_array($result)){
array_push($history_array, $row);
}
}
?>


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...