VegasKiller Posted June 18, 2013 Posted June 18, 2013 (edited) So I added a weather mod into my game and changed the weather table to have the cloumn city alongside weather and remaining. The cron is taking 1 away from remaining every minute but it is not changing the weather when the remaining gets to 0, so now I have all my remaining columns at 0. I think the error is from adding in the city column as before it was changing weather for one area and now its meant to change it for over 20. Here is the code. function update_weather() { /// Weather Starts Here /// mysql_query("UPDATE weather SET remaining=remaining-1 WHERE remaining>0"); $wi=mysql_query("SELECT ws.*,w.* FROM weather ws LEFT JOIN weathers w ON ws.weather=w.w_id LIMIT 1;"); $w=mysql_fetch_array($wi); if($w['remaining'] == 0) { $weather=mysql_fetch_array(mysql_query("SELECT * FROM weathers ORDER BY rand() LIMIT 1;")); $chance=rand(1,$weather['w_chance']*20); if($weather['w_chance'] < $chance) { $weather=mysql_fetch_array(mysql_query("SELECT * FROM weathers ORDER BY rand() LIMIT 1;")); } $chance=rand(1,$weather['w_chance']*20); if($weather['w_chance'] < $chance) { $weather=mysql_fetch_array(mysql_query("SELECT * FROM weathers ORDER BY w_chance DESC LIMIT 1;")); } $w2c=$weather['w_id']; $time = rand(1,120); mysql_query("UPDATE weather SET weather={$w2c} LIMIT 1;"); mysql_query("UPDATE weather SET remaining=$time WHERE remaining=0"); } /// Weather Ends Here /// } in ajax where it should show the image of the current weather, it is not. I am guessing it is not fetching the weather data. function display_weather(){ //$ws=mysql_query("SELECT weather,remaining FROM weather"); // Formulate Query $query = sprintf("SELECT weather,remaining FROM weather WHERE city='$stats_array[city]'"); // Perform Query $ws = mysql_query($query); // Error Check if (!$ws) { echo 'Could not run query: ' . mysql_error(); exit; } // if $rws=mysql_fetch_array($ws); //$tws=mysql_query("SELECT w_name FROM weathers WHERE w_id={$rws['weather']}"); // Formulate Query $query = sprintf("SELECT w_name FROM weathers WHERE w_id=%d", mysql_real_escape_string($rws['weather']) ); // Perform Query $tws = mysql_query($query); // Error Check if (!$tws) { echo 'Could not run query: ' . mysql_error(); exit; } // if $fws=mysql_fetch_array($tws); echo "<center><img width=60 height=60 alt='Current Weather For Next {$rws['remaining']} M(s).' title='{$fws['w_name']} For Next {$rws['remaining']} M(s).' src='../beta/layout_images/weather/{$rws['weather']}.png'/></center>"; } Edited June 18, 2013 by VegasKiller Got script to load in ajax, but now it is not fetching data to show the weather image, name or time remaining. Quote
Magictallguy Posted July 5, 2013 Posted July 5, 2013 Try appending an or die/exit mysql_error to the mysql_query()'s Was: mysql_query($someQuery); Becomes: mysql_query($someQuery) or exit(mysql_error()); Any errors flagged from your queries will actually stop the script and allow you to debug Quote
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.