yuckysocks Posted March 15, 2009 Share Posted March 15, 2009 Hi there, I just got a project to work, and want to know where I could have improved the code. Thanks for taking a look: This is a Cron every hour and sets up the database: <?php // displays all the file nodes $xml=simplexml_load_file('http://www.weather.gov/xml/current_obs/KBOS.xml'); if ($xml) { //sets up all the variables I need for the SQL addendum $weather = $xml->weather; $temp = $xml->temp_f; $wind = $xml->wind_mph; $date = $xml->observation_time; } //error catching else { echo "Oops, bad input"; } $db = mysql_connect('blah, blah, blah') or die(mysql_error()); mysql_select_db('table') or die(mysql_error()); mysql_query("INSERT INTO weatherdata (date, weatherstr, temp, wind) VALUES ('$date', '$weather', '$temp', '$wind')"); mysql_close($db); ?> And the next part fetches the data I want and makes it as 45, 48, 59, 64.... for the last 35 values. <?php //open connection $db = mysql_connect(blah, blah, blah) or die(mysql_error()); mysql_select_db('tables') or die(mysql_error()); $result = mysql_query("SELECT * FROM weatherdata ORDER BY id DESC LIMIT 35"); $row = (mysql_fetch_array($result)); while($row = (mysql_fetch_array($result))){ $output[] = $row['temp']; } $reverse = (array_reverse($output)); $csv = implode(", ", $reverse); ?> I want to know if this leaves memory open, if I could have done this more elegantly, or anything like that. I have the FUNCTION down, now I'm worried about learning good FORM. Thanks! -Alex Quote Link to comment https://forums.phpfreaks.com/topic/149548-efficient-coding/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.