I am trying to create a php array that holds all fields and rows of the mysql query that is executed. I have tried the below syntax, but when I do a echo nothing is displayed.
<?php
$con=mysqli_connect("server", "user", "pass", "db");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT * FROM testTable LIMIT 10";
$result = mysqli_query($con,$sql);
foreach($array as $index => $value){
echo "<p>\$index: {$index}; \$value: {$value[0]}</p>";
var_export($value);
}
mysqli_free_result($result);
mysqli_close($con);
?>```
If I change the foreach loop and use $result instead of $array - it will print on screen
$index: 0; $value:
$index: 1; $value:
And I want the actual elements (or is values the right word) of the array.
$array? Surely you meantforeach($result as $index => $value){? You're not doing anything with the result of the query.