Jump to content

Comparing current date minus six weeks in php against record in mysql


RyanW

Recommended Posts

Hi there imhaving problems with dates. I've really pieced this all together from bits and pieces of articles and howtos from around the net. Lemme try and explain what i want it to do. We have certain events in a game called raids that we do and i log them into the database. The raid table has many fields one of them is the raid date named "RaidDate"and it is stored as a type "datetime" and thus stores a value of "2008-11-27 00:00:00" for example. Now in my code what im trying to do is to check all the raid events and check for any raid that has happened within the last 6 weeks if it finds any i want to then check to see if it was a "bonus" raid which is just a boolean value in the raid data it will then calculate details of it to display. if it was not a bonus raid i want it to just calculate other details. If there was no raids within the last 6 weeks i want it to set certain values to 0. At the moment it's giving me odd results and im unsure why. Im really not sure about getting the time if that is correct.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Avatars of Hate</title>

</head>
<body>
<center>
<? 
include 'config.php';
include 'opendb.php';

mysql_select_db($dbname);

$RS_query = mysql_query("SELECT name, class FROM members WHERE Status = 'Active' ORDER BY Name ASC") or die('Error, Query Members failed');
$RS = mysql_fetch_array($RS_query);

$RS1_query = mysql_query("SELECT * FROM raids ORDER BY RaidDate DESC") or die('Error, Query Raid failed');
$RS1 = mysql_fetch_array($RS1_query);

$TotalPossiblePoints=0;
$RaidCount=0;
$BonusRaids=0;
$TotalPossibleBonusPoints=0;
$sixweeksago = date("Y-m-d H:m:s", strtotime("-6 weeks"));

while(!($RS1==0))
{

  	if ($RS1["RaidDate"] < $sixweeksago)
	{
//$RS1=mysql_fetch_array($RS1_query);



    

    	if ($RS1["Bonus"] == 1)
    	{
      	$BonusRaids = $BonusRaids + 1;
	$TotalPossibleBonusPoints = $TotalPossibleBonusPoints + $RS1["RaidLength"]+2;
	}
    	
	else if($RS1["Bonus"] == 0)

  		{
	$RaidCount=$RaidCount +1;
    	$TotalPossiblePoints = $TotalPossiblePoints + $RS1["RaidLength"] + 2;
	} 
}
else
{
$TotalPossiblePoints=0;
$RaidCount=0;
$BonusRaids=0;
$TotalPossibleBonusPoints=0;
}
  $RS1=mysql_fetch_array($RS1_query);


}
include 'closedb.php';
?>
<TABLE>
<tr>
<TD ALIGN=CENTER COLSPAN=5>Total Possible Attendance Points: <? echo $TotalPossiblePoints;?></TD>
</tr>
<tr>
<td align=center colspan=5>over <? echo $RaidCount;?> raids.</td>
</tr>
<tr>
<TD ALIGN=CENTER COLSPAN=5>Total Possible Bonus Points: <? echo $TotalPossibleBonusPoints;?></TD>
</tr>
<tr>
<td align=center colspan=5>over <? echo $BonusRaids;?> bonus raids.</td>
</tr>
<tr>
<td colspan=5></td>
</tr>
<TR>
<TD width=125>Name</TD><TD width=75>Attendance</TD><TD ALIGN=CENTER width=50>%</TD><TD width=50 align=center>Loots</TD><TD width=50 align=center>LAR</TD>
</TR>
</TABLE>
</div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.