Hello,
I’m building a weather website that is updated by a friend of mine through a SQL database, it’s fairly straight forward, he logs into a secured page and inputs data such as the high, low, current condition, etc…
I’ve got all that setup, but I want to take it one step further now. I need the script to grab a SQL entry only if it is from the current day and if there is no entry corresponding with that day, to then grab the data from weather.gov.
I’m not terribly skilled with php, and thus I’m having trouble finding a way to implement this. Any help would be appreciated.
Thank you
Here is the code I use to store the info into the database:
[php]
$high = $_GET[‘high’];
$low = $_GET[‘low’];
$pic = $_GET[‘pic’];
$desc = $_GET[‘desc’];
$chance = $_GET[‘chance’];
$connection = mysql_connect(“localhost”,“user”,“pass”) or die(mysql_error());
mysql_select_db(“a1336838_weather”) or die(mysql_error());
$query = “INSERT INTO weather_info VALUES(’$high’,’$low’,’$pic’,’$desc’,’$chance’, NOW())”;
$result = mysql_query($query);
echo “Data has been Stored in your database”;
[/php]
Here is the code I use to call the entries from the database:
[php]
mysql_connect(“localhost”,“user”,“pass”) or die(mysql_error());
mysql_select_db(“user”) or die(mysql_error());
$data = mysql_query(“SELECT * FROM weather_info ORDER BY datefield DESC LIMIT 1”)
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
Print “
”.$info[‘high’].“°
Print “
“.$info[‘low’].“°
Print “
Print “
Print “
} [/php]