Jump to content

No result. What's going on?


Pi_Mastuh

Recommended Posts

I'm working on a dual arena for my site where users can fight against the computer. This is the page that does all the calculations and stuff then updates the data in the database and goes to another page based on results. It's kind of hard to explain. All my echos are coming back as 0 and it's not re-directing to another page, anyone know what's wrong?

[code]<?php
//Database
include ("config.php");
session_start();
$session = session_id();

$db_name = "db175253437";

$conn = mysql_connect("db491.perfora.net", "****" ,"****", true) or die("Couldn't connect");

mysql_select_db($db_name, $conn) or die("Couldn't select Database1.");


$SQL = "SELECT * FROM CurrentFights WHERE userID = '".$_POST['preuserID']."'";
$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$numberF = mysql_num_rows($result);
$query_data = mysql_fetch_array($result);
$turn = $query_data['turn'];
$petID2 = $query_data['petID'];
$cID2 = $query_data['cID'];

$SQL = "SELECT * FROM LastRound WHERE userID = 'preuserID'";
$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$numberF = mysql_num_rows($result);
$query_data = mysql_fetch_array($result);
$pLDmg = $query_data['pDmg'];
$cLDmg = $query_data['cDmg'];

$SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '".$_POST['monopetID']."'";
$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$query_data = mysql_fetch_array($result);
$hp = $query_data['hp'];
$totalHP = $query_data['totalHP'];
$lvl = $query_data['monopetLevel'];
$xp = $query_data['xp'];
$petName = $query_data['monopetName'];

$SQL = "SELECT * FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'";
$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$query_data = mysql_fetch_array($result);
$atkValue = $query_data['atkValue'];
$defValue = $query_data['defValue'];
$itemName = $query_data['itemName'];

$SQL = "SELECT * FROM Challengers WHERE cID = '".$_POST['cID']."'";
$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$query_data = mysql_fetch_array($result);
$cHP = $query_data['cHP'];
$cLvl = $query_data['cLvl'];
$cName = $query_data['cName'];
$cWepVal = $query_data['cWepVal'];

$SQL = "SELECT * FROM CurrentFights WHERE userID = 'preuserID'";
$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
$numberF = mysql_num_rows($result);
$query_data = mysql_fetch_array($result);
$cCurHP = $query_data['cHP'];

//Get the damage ammount
$max = $lvl+$atkValue;
$dmg1 = rand(0, $max);
$dmg2 = rand(0, $max);
echo "Max: $max<br>dmg1: $dmg1<br>dmg2: $dmg2";
//What kind of attack are they doing - figure out their damage
if ($atkType == "Fierce")
{
$dmg = $dmg1 + $dmg2;
}
elseif ($atkType == "Cautious")
{
if ($dmg1 > $dmg2)
{
$dmg = $dmg1;
}
elseif ($dmg1 < $dmg2)
{
$dmg = $dmg2;
}
elseif ($dmg1 == $dmg2)
{
$dmg = $dmg1;
}
$def = $lvl;
}
elseif ($atkType == "Defensive")
{
if ($dmg1 > $dmg2)
{
$dmg = $dmg1-$dmg2;
}
elseif ($dmg1 < $dmg2)
{
$dmg = $dmg2-$dmg1;
}
elseif ($dmg1 == $dmg2)
{
$dmg = 0;
}
$def = $lvl*2;
}
else
{
echo "Error: Invalid attack type";
}
echo "dmg: $dmg<br>def: $def";

//Opponent's dmg
$max2 = $cLvl+$cWepVal;
$Cdmg1 = rand(0, $max2);
$Cdmg2 = rand(0, $max2);
$CType = rand(1, 3);
echo "max2: $max2<br>cdmg1: $Cdmg1<br>cdmg2: $Cdmg2<br>ctype: $ctype";

if ($CType == "3")
{
$Cdmg = $Cdmg1 + $Cdmg2;
}
elseif ($CType == "2")
{
if ($Cdmg1 > $Cdmg2)
{
$Cdmg = $dCmg1;
}
elseif ($Cdmg1 < $Cdmg2)
{
$Cdmg = $Cdmg2;
}
elseif ($Cdmg1 == $Cdmg2)
{
$Cdmg = $Cdmg1;
}
$Cdef = $cLvl;
}
elseif ($CType == "1")
{
if ($Cdmg1 > $Cdmg2)
{
$Cdmg = $Cdmg1-$Cdmg2;
}
elseif ($Cdmg1 < $Cdmg2)
{
$Cdmg = $Cdmg2-$Cdmg1;
}
elseif ($Cdmg1 == $Cdmg2)
{
$Cdmg = 0;
}
$Cdef = $cLvl*2;
}
else
{
echo "Error: Invalid attack type for opponent";
}

echo "Cdmg: $Cdmg<br>Cdef: $Cdef";
//find out the final result
if ($dmg > $Cdef)
{
$Pdmg = rand($Cdef, $dmg);
}
elseif ($dmg < $Cdef)
{
$Pdmg = rand($dmg, $Cdef);
}
elseif ($dmg == $Cdef)
{
$Pdmg = $dmg;
}

if ($Cdmg > $def)
{
$Ctdmg = rand($def, $Cdmg);
}
elseif ($Cdmg < $def)
{
$Ctdmg = rand($Cdmg, $def);
}
elseif ($Cdmg == $def)
{
$Ctdmg = $Cdmg;
}

$turn++;
$newHP = $hp-$Ctdmg;
$cnewHP = $cCurHP-$Pdmg;
if ($newHP > 0 and $cnewHP > 0)
{
mysql_query("UPDATE CurrentFights SET turn = '$turn' WHERE userID = '$preuserID'");
mysql_query("UPDATE CurrentFights SET cHP = '$cnewHP' WHERE userID = '$preuserID'");
mysql_query("UPDATE chibifriendspets SET hp = '$newHP' WHERE monopetID = '$monopetID'");
mysql_query("UPDATE LastRound SET pDmg = '$Pdmg' WHERE userID = '$preuserID'");
mysql_query("UPDATE LastRound SET cDmg = '$Ctdmg' WHERE userID = '$preuserID'");

header("Location:arena4.php");
}
elseif ($newHP <= 0 and $cnewHP <= 0)
{
$fight = "Draw";
header("Location:arena6.php");
}
elseif ($newHP <= 0 and $cnewHP > 0)
{
$fight = "Lose";
header("Location:arena6.php");
}
elseif ($newHP > 0 and $cnewHP <= 0)
{
$fight = "Win";
header("Location:arena6.php");
}
?> [/code]
Link to comment
Share on other sites

[quote]It's kind of hard to explain.[/quote]

Then its kinda hard to help. Your code is pretty hard to follow and are you sure you want to be running multiple queries like that?

Narrow your problem down some and please give us a better decription of your exect problem.
Link to comment
Share on other sites

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.