I have been writing a code snippet of PHP in HTML which iterates an array inside another array (data from mysql). But when I run the code, it gives the following two errors.
Undefined variable Array to string conversion in ...... Following is my code.
$sql = "SELECT * FROM person";
$result = mysqli_query($conn, $sql);
$resultDataSet = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
array_push($resultDataSet, $row);
}
if ($type == "HTML") {
$htmlSerialize = "
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<?php foreach($resultDataSet as $value): ?>
<tr>
<th><?php=?".$value['Name']." ?></th>
<th><?php=?".$value['Age']." ?></th>
<th><?php=?".$value['City']." ?></th>
</tr>
<?php endforeach; ?>
</table>";
echo $htmlSerialize;
}
Also following are the errors.
What is the error I have made? How can I solve this?
Edited
Following is the var dump of $resultDataSet
array (size=2)
0 =>
array (size=8)
0 => string '1' (length=1)
'ID' => string '1' (length=1)
1 => string 'Akila' (length=5)
'Name' => string 'Akila' (length=5)
2 => string '22' (length=2)
'Age' => string '22' (length=2)
3 => string 'Mount Lavinia' (length=13)
'City' => string 'Mount Lavinia' (length=13)
1 =>
array (size=8)
0 => string '2' (length=1)
'ID' => string '2' (length=1)
1 => string 'Randil' (length=6)
'Name' => string 'Randil' (length=6)
2 => string '23' (length=2)
'Age' => string '23' (length=2)
3 => string 'Colombo' (length=7)
'City' => string 'Colombo' (length=7)