I’m trying to store the date from DateTime from PhpMyAdmin into an array in my code. For some reason, It only applies the last date to the position [0] from my array. Please help.
This is what I tried:
$id = $_SESSION['userId'];
$dBname = "infosensor";
$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBname);
$sql = "SELECT dias FROM `$id`;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
$horario = $horario .'"'.(date('H:i:s', strtotime(str_replace('.', '-', $row['dias'])))). '",';
$arr = array($horario);
}
}
echo $arr[0];
The result that I get from the code I tried is:
"16:29:47","16:30:07","16:33:55","16:34:25",...
All of the at position [0]
I would need to when going into the array -> arr[0] = “16:29:47” when I want the position 1 I just use arr[1] = “16:30:07″…
3
Answers
Try changing this line like this:
First you need to initialise $arr = []
Then you can achieve this by explode.
Output
Like this