$row = $overview_response->fetch_array(MYSQLI_NUM);
returns the following as an array:
Array ( [0] => 12 [1] => username [2] => email [3] => a53ccb24bfb1135eb45e675464f948 [4] => Test message [5] => 1 [6] => Test subject [7] => 2016-01-29 15:35:02 )
How could i access the parameters like only the username?
Been testing the following before:
foreach ($row as $key) {
echo $key[1];
}
Your $row
is an array so you can walk through the values using foreach()
. However the values of your array are not arrays.
so this command echo $key[1]
is invalid as it tries to access the first element of $key
but $key
is a string.
You can get to your values by using something like:
$id = $row[0];
$username = $row[1];
// and so on
Your code
$row = $overview_response->fetch_array(MYSQLI_NUM);
returns to you an array. You can access key in array by it's index. I suppose username
is value with key 1.
$row = $overview_response->fetch_array(MYSQLI_NUM);
var_dump($row[1]);
This is the simpliest way.
Other way can be using MYSQLI_ASSOC
constant, which will return string keys instead of numeric keys:
$row = $overview_response->fetch_array(MYSQLI_ASSOC);
var_dump($row);
// after that you can still access username by key,
// but now it will be the name of a corresponding field
var_dump($row['username']); // if field is called `username`