Jump to content

Recommended Posts

Im sorry if this is kinda long winded but im really struggling. Ive been dealing with php/mysql for years but only editing tiny little bits so im still basically a novice. Ive bene left a task to convert an old site from asp to php and for the most part its gone well apart from this file. Ive tried for 4 days in vein to convert it however im really struggling with some of it. I was hoping somone here who may know both languages could see any glaring mistakes ive made. Some of the results are not as i expected especially in the later parts. I really hope someone can lend some insight and correct some of my mistakes

 

Original ASP

<!-- #include file ="db.asp" -->
<html>
<head>
<title>Avatars of Hate</title>
<LINK REL=StyleSheet HREF="AoH.css" TYPE="text/css" MEDIA=screen>
</head>
<body>
<center>


<%
Set MyConn = server.createobject("ADODB.Connection")
MyConn.OPEN db

Set RS = MyConn.Execute ("SELECT Name, Class From Members WHERE Status = 'Active' ORDER BY Name ASC")

MySQL = "SELECT * FROM Raids ORDER BY RaidDate DESC"
Set RS1 = MyConn.Execute (MySQL)

TotalPossiblePoints = 0
RaidCount = 0
BonusRaids = 0
TotalPossibleBonusPoints = 0

WHILE NOT RS1.EOF
IF RS1("RaidDate") < Date()-42 THEN
	RS1.MoveNext
ELSE
	IF RS1("Bonus")=True THEN
		BonusRaids = BonusRaids + 1
		TotalPossibleBonusPoints = TotalPossibleBonusPoints + RS1("RaidLength") + 2
	ELSE
		RaidCount = RaidCount + 1
		TotalPossiblePoints = TotalPossiblePoints + RS1("RaidLength") + 2
	END IF
	RS1.Movenext
END IF
WEND
%>
<TABLE>
<tr>
<TD ALIGN=CENTER COLSPAN=5>Total Possible Attendance Points: <%=TotalPossiblePoints%></TD>
</tr>
<tr>
<td align=center colspan=5>over <%=RaidCount%> raids.</td>
</tr>
<tr>
<TD ALIGN=CENTER COLSPAN=5>Total Possible Bonus Points: <%=TotalPossibleBonusPoints%></TD>
</tr>
<tr>
<td align=center colspan=5>over <%=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>
<%


While not RS.EOF
Attendance = 0
Loots = 0
BonusPoints = 0
Set RS3 = MyConn.Execute ("SELECT * FROM Raids ORDER BY RaidDate DESC")
WHILE NOT RS3.EOF
	IF RS3("RaidDate") < Date()-42 THEN
		RS3.MoveNext
	ELSE
		IF RS3("Bonus") = true THEN
			Set RS2 = MyConn.Execute ("SELECT " & RS3("RaidNum") & " FROM Attendance WHERE Name = '" & RS(0) & "'")
			BonusPoints = BonusPoints + RS2(0)
			RS2.CLOSE
			IF RS3("Loot1Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot2Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot3Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot4Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot5Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot6Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot7Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot8Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot9Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot10Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot11Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot12Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot13Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot14Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot15Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot16Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot17Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot18Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot19Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot20Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
		ELSE
			Set RS2 = MyConn.Execute ("SELECT " & RS3("RaidNum") & " FROM Attendance WHERE Name = '" & RS(0) & "'")
			Attendance = Attendance + RS2(0)
			RS2.CLOSE
			IF RS3("Loot1Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot2Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot3Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot4Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot5Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot6Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot7Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot8Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot9Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot10Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot11Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot12Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot13Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot14Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot15Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot16Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot17Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot18Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot19Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
			IF RS3("Loot20Winner") = RS(0) THEN
				Loots = Loots + 1
			END IF
		END IF
		RS3.MoveNext
	END IF
WEND
RS3.CLOSE
IF Attendance = 0 THEN
	AttendancePercent = 0
	LAR = 0
ELSE
	Attendance = Attendance + BonusPoints
	TotalPointsWithBonus = TotalPossiblePoints + BonusPoints
	AttendancePercent = (Attendance / TotalPointsWithBonus) * 100
	IF Loots = 0 THEN
		LAR = formatnumber(AttendancePercent * 1.5, 0)
	ELSE
		LAR = formatnumber(AttendancePercent / Loots, 0 )
	END IF
END IF
IF Attendance = 0 THEN
	RS.MoveNext
ELSE
	Response.Write "<TR><TD><A HREF=Memberdetail.asp?Name=" & RS(0) & ">" & RS(0) & "</A></TD>"
	Response.Write "<TD align=center>"
	Response.Write Attendance & "</TD>" & vbcrlf
	Response.Write "<TD align=center>" & formatnumber(AttendancePercent, 2) & "</TD>"
	Response.Write "<TD align=center>" & Loots & "</TD>" & vbcrlf
	Response.Write "<TD align=center><b>" & LAR & "</b></TD>" & vbcrlf
	Response.Write "</TR>"
	RS.Movenext
END IF
WEND
%>
<tr>
<td colspan=5 align=center><a href=menu.asp>Main Menu</a></td>
</tR>
</TABLE>
</div>
</body>
</html>

 

And this is my attempt at conversion

 

<!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);


$result = mysql_query("SELECT * FROM raids ORDER BY RaidDate ASC");
$row = mysql_fetch_assoc($result);

$TotalPossiblePoints=0;
$RaidCount=0;
$BonusRaids=0;
$TotalPossibleBonusPoints=0;

while ($row = mysql_fetch_assoc($result)) 

{


$var1 = strtotime($row['RaidDate']);
$dateofraid = date("Y-m-d", $var1);


$var2 = strtotime('6 weeks ago');
	$datesixweeksasgo = date('Y-m-d', $var2);



  	if ( $dateofraid > $datesixweeksasgo ) 

	{


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

  		{
	$RaidCount=$RaidCount +1;
    	$TotalPossiblePoints = $TotalPossiblePoints + $row["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>
<tr>
<TD ALIGN=CENTER COLSPAN=5>Total Possible Bonus Points: <? echo $TotalPossibleBonusPoints;?></TD>
</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>
<? 
include 'config.php';
include 'opendb.php';




$result2 = mysql_query("SELECT * FROM members ORDER BY Name ASC");

$row2 = mysql_fetch_assoc($result2);


while ($row2 = mysql_fetch_assoc($result2)) 
{

$Attendance=0;
  	$Loots=0;
  	$BonusPoints=0;

$result3 = mysql_query("SELECT * FROM raids ORDER BY RaidDate ASC");
$row3 = mysql_fetch_assoc($result3);

while ($row3 = mysql_fetch_assoc($result3)) 
{


	$var1 = strtotime($row3['RaidDate']);
	$dateofraid = date("Y-m-d", $var1);


	$var2 = strtotime('6 weeks ago');
		$datesixweeksasgo = date('Y-m-d', $var2);



  		if ( $dateofraid > $datesixweeksasgo )

		{

		if ($row3["Bonus"]  == true)
		{
		$result4 = mysql_query("SELECT ".$row3["RaidNum"]." FROM attendance WHERE Name = '".$row5["Name"]."'");  
    		$row4 = mysql_fetch_array($result4, MYSQL_BOTH);
		$BonusPoints = $BonusPoints + $row4[0];

		 	if ($row3["Loot1Winner"] == $row2["Name"])
      			{
	  		$Loots = $Loots + 1;


      			} 


		}

		else if ($row3["Bonus"]  == false)
		{
		$result6 = mysql_query("SELECT ".$row3["RaidNum"]." FROM attendance WHERE Name = '".$row5["Name"]."'");  
		$row6 = mysql_fetch_array($result6, MYSQL_BOTH);
		$Attendance= $Attendance + $row6[0];

			if ($row3["Loot1Winner"] == $row2["Name"])
      			{
	  		$Loots = $Loots + 1;

      			} 
		}
		else
		{
		echo "UHOHHHHH";

		}


	}

}
}
include 'closedb.php';
?>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/134898-asp-to-php-conversion-woes/
Share on other sites

Ok where to start, The following line

 

$BonusPoints = $BonusPoints + $row4[0];

 

i caat seem to get this to calcualte and when i do an echo on $row4[0] i get no result.

 

i include the structures for the database if its useful to you

raids table

raids.jpg

 

members table

members.jpg

 

attendance table

attendance.jpg

$result4 = mysql_query("SELECT ".$row3["RaidNum"]." FROM attendance WHERE Name = '".$row5["Name"]."'");  

 

$row5 is nowhere to be seen in your script... So it is likely it is empty and this query fails.

 

Here's a tip for you.

Do queries like this:

 

$query = "SELECT...." //put your qyery here
$result = mysql_query($query) or die(mysql_error()." :$query");

 

this will show error message if query fails alongside with the query, so that you can easily heck if the query has been created correctly.

That sort of fixed one issue. It did use to calcualte and your right now i get a string of values however it doesnt seem to be cyling through all of the values more it seems to be listing the first one and repeating it over and over. Because although u cant see it in the image all the way over near the r73 r74 r75 etc the values arent 0.00000 they are 7.00000 yet the page only outputs 0.00000

 

And by the way i readded this

 

$result5 = mysql_query("SELECT Name, Class From members WHERE Status = 'Active' ORDER BY Name ASC");

$row5 = mysql_fetch_assoc($result5);

 

the page can be viewed here http://www.avatarsofhate.com/rawr/index.php sorry for the horrific looking output i did mention im a noob!

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.