Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create weather table record when database table empty #175

Merged
merged 2 commits into from
Mar 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cron/weather_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@
$conn->query($query);
echo "\033[36m".date('Y-m-d H:i:s'). "\033[0m - Database Updated \n";
//update weather table
$query = "update weather SET sync = '0', location = '{$location}', c = '{$weather_c}', wind_speed = '{$wind_speed}', title = '{$title}', description = '{$description}', sunrise = '{$sunrise}', sunset = '{$sunset}', img = '{$icon}' WHERE id = '1' LIMIT 1";
$query = "SELECT * FROM weather";
$result = $conn->query($query);
$wcount = $result->num_rows;
if ($wcount == 0) {
$query = "INSERT INTO weather VALUES(1, 0, '{$location}', '{$weather_c}', '{$wind_speed}', '{$title}', '{$description}', '{$sunrise}', '{$sunset}', '{$icon}', '{$date_time}');";
} else {
$query = "update weather SET sync = '0', location = '{$location}', c = '{$weather_c}', wind_speed = '{$wind_speed}', title = '{$title}', description = '{$description}', sunrise = '{$sunrise}', sunset = '{$sunset}', img = '{$icon}' WHERE id = '1' LIMIT 1";
}
$conn->query($query);
}else {
echo "\033[36m".date('Y-m-d H:i:s'). "\033[0m -Current Weather data was not downloaded \n";
Expand Down Expand Up @@ -154,4 +161,4 @@
echo " \n";
echo "\033[36m".date('Y-m-d H:i:s'). "\033[0m - Weather Update Script Finished \n";
if(isset($conn)) { $conn->close();}
?>
?>