Jump to content
MakeWebGames

Weather Script Not Running Properly, Please Help


VegasKiller

Recommended Posts

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 by VegasKiller
Got script to load in ajax, but now it is not fetching data to show the weather image, name or time remaining.
Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...