I'm having trouble iterating through a PHP array in order to display a chart. Right now, my code is only resulting in the display of one column in the chart (this column is displaying correctly), but I can't seem to get other columns to display.
This is my code right now (in a php section at the top of my html page). I know that the issue is with this section of code, because the chart is rendering perfectly, but just not adding a column for each record in the table.
I'd really appreciate any insight into the mistakes I'm making here. Thank you.
$valueAnimalType = $_POST['animaltype'];
$connect = mysqli_connect("127.0.0.1","____","_____",3306);
$result = mysqli_query($connect,"SELECT * FROM DISPOSAL");
$datas = array();
if (mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$datas[] = $row;
}
foreach ($datas as $data){
$datas = array(
array('y' => $data[$valueAnimalType], "label" => $data['DisposalName'] ));
}
}
mysqliis significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_queryinterface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)and$db->prepare("…")The procedural interface is an artifact from the PHP 4 era whenmysqliAPI was introduced and should not be used in new code.