Reputation: 25
How do i set the value of echo $row['$d']; to auto to follow datetime. For example if date = Apr so the value inside echo should be $row['Apr']; without change manualy.
<?php
date_default_timezone_set("Asia/Kuala_Lumpur");
$today = strtotime("today");
$d=strtotime("-1 Month");
include("config/view-graph.php");
$sql = "SELECT * FROM settings where id = '1'";
$result = $conn->query($sql); if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo date("M", $d). "<br>";
echo $row['Apr'];
} } else { echo "0 results"; } $conn->close(); ?>
Upvotes: 0
Views: 19
Reputation: 72269
Assign it to a variable and use it:-
$day_name =date("M", $d). "<br>";
echo $row[$day_name];
Upvotes: 1