Display SQL database entry for current day only


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:
$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”;

Here is the code I use to call the entries from the database:
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 “

Print “
Print “
<img id=‘pic’ src='Images/”.$info[‘pic’].”.png’ width=‘165’ height=‘155’/>
Print “
Print “
”.$info[‘chance’]."% Chance of Precpitation
} [/php]

$data = mysql_query(“SELECT * FROM weather_info where datefield = now()”);
// display record
// place the script for collecting the data from weather.gov

Ahhh, thank you I completely forgot about “if” and “else”

u r welcome, glad it helped.

Sponsor our Newsletter | Privacy Policy | Terms of Service