Emperio
04-10-2008, 04:21 PM
Hey guys I got this grid based code, but it got something what I don't understand. When I use this {
$player=$_SESSION['player'];
$sfield="SELECT * from km_sfield where name='$player'";
$sfield2=mysql_query($sfield) or die(mysql_error());
$sfield3=mysql_fetch_array($sfield2) or die(mysql_error()); above another code the part below it does not show! can someone explain me why??
<?php
include 'connect.php';
session_start();
?>
<link rel="stylesheet" href="style.css" type="text/css">
<?php
//game map test
//set the grid size
$grid_y = (int)30;
$grid_x = (int)30;
//x and y rows to display at once
$display_rows = (int)15;
//default display cordinate
$x = (int)1;
$y = (int)1;
$param_x = $_REQUEST["xcord"];
$param_y = $_REQUEST["ycord"];
if (isset($param_x) && isset($param_y)) {
//validate that the parameter is a legit point
if (($param_x <= $grid_x) && ($param_x >= 1) && ($param_y <= $grid_y) &&($param_y >= 1)) {
$x = (int)$param_x;
$y = (int)$param_y;
}
}
//the grid position desired will be set to display in the center of the viewable grid
$display_half = round($display_rows / 2);
$other_half = $display_rows - $display_half;
//to display the target in the middle, you have to get the number of rows to display before and after it.
//some simple math to take care of that.
$start_x = ($x - $display_half) +1;
$end_x = $x + $other_half;
//if the $start_x variable is less than 1 the grid would be in the negatives. so set it to 1
if ($start_x < 1) {
$start_x = 1;
$end_x = $display_rows;
} else
//if $end_x is off the grid we have to compensate and add the remaining rows to the start.
if ($end_x > $grid_x) {
$extra = $end_x - $grid_x;
$end_x = $grid_x;
$start_x = $start_x - $extra;
}
//same applies for the y axis
$start_y = ($y - $display_half) +1;
$end_y = $y + $other_half;
if ($start_y < 1) {
$start_y = 1;
$end_y = $display_rows;
} else
if ($end_y > $grid_y) {
$extra = $end_y - $grid_y;
$end_y = $grid_y;
$start_y = $start_y - $extra;
}
//showing the current parameters
echo "X $x - Y $y<br>";
?>
<table width="750" cellspacing="0" cellpadding="2" border="1">
<?php
//these 2 for loops represent the y and x axis
//using the data collected above the loops will properly display the grid
for ($Ty = $start_y; $Ty <= $end_y; $Ty++) {
//start new row
echo '<tr>';
for ($Tx = $start_x; $Tx <= $end_x; $Tx++) {
//show grid
DisplayGrid($Tx,$Ty);
}
echo '</tr>';
}
?>
</table>
<?php
This is the part of the code which don't shows the part below it{
$player=$_SESSION['player'];
$sfield="SELECT * from km_sfield where name='$player'";
$sfield2=mysql_query($sfield) or die(mysql_error());
$sfield3=mysql_fetch_array($sfield2) or die(mysql_error());
}
This doesn't shows up{
function DisplayGrid($gridx,$gridy) {
global $x, $y;
$bgcolor = 'background="http://conquerorsofsanvia.890m.com/img"';
//highlight current select grid coordinate
if ($gridx == $x && $gridy == $y) {
$bgcolor = 'background="http://conquerorsofsanvia.890m.com/img"';
}
if ($gridx == $sfield3[x] && $gridy == $sfield3[y]) {
$imgsrc = 'img src="http://conquerorsofsanvia.890m.com/img"';
}
echo "<td width=\"50\" height=\"50\" $bgcolor align=center valign=bottom><a style='line-height:1em;width:75%;height:75%;display:block;' href=\"grid.php?xcord=$gridx&ycord=$gridy\"></a><br><font size=1 color='blue'>($gridx,$gridy)</font></td>";
}
print "<table class='maintable'><tr class='headline'><td><center>Deploy Soldiers</center></td></tr>";
print "<tr class='mrw'><td>";
print "Each unit contains a squad of 100 units from the same class.<br>";
print "<form action='dplsoldiers.php' method='post'>";
print "<SELECT NAME='class'>";
print "<OPTION VALUE='Pikeman'>Pikeman";
print "<OPTION VALUE='Archers'>Archers";
print "<OPTION VALUE='Swordsman'>Swordsman";
print "<OPTION VALUE='Cavalry'>Cavalry";
print "</SELECT>";
print "<input type='submit' name='submit' value='submit'></form>";
print "</td></tr></table>";
}
?>
$player=$_SESSION['player'];
$sfield="SELECT * from km_sfield where name='$player'";
$sfield2=mysql_query($sfield) or die(mysql_error());
$sfield3=mysql_fetch_array($sfield2) or die(mysql_error()); above another code the part below it does not show! can someone explain me why??
<?php
include 'connect.php';
session_start();
?>
<link rel="stylesheet" href="style.css" type="text/css">
<?php
//game map test
//set the grid size
$grid_y = (int)30;
$grid_x = (int)30;
//x and y rows to display at once
$display_rows = (int)15;
//default display cordinate
$x = (int)1;
$y = (int)1;
$param_x = $_REQUEST["xcord"];
$param_y = $_REQUEST["ycord"];
if (isset($param_x) && isset($param_y)) {
//validate that the parameter is a legit point
if (($param_x <= $grid_x) && ($param_x >= 1) && ($param_y <= $grid_y) &&($param_y >= 1)) {
$x = (int)$param_x;
$y = (int)$param_y;
}
}
//the grid position desired will be set to display in the center of the viewable grid
$display_half = round($display_rows / 2);
$other_half = $display_rows - $display_half;
//to display the target in the middle, you have to get the number of rows to display before and after it.
//some simple math to take care of that.
$start_x = ($x - $display_half) +1;
$end_x = $x + $other_half;
//if the $start_x variable is less than 1 the grid would be in the negatives. so set it to 1
if ($start_x < 1) {
$start_x = 1;
$end_x = $display_rows;
} else
//if $end_x is off the grid we have to compensate and add the remaining rows to the start.
if ($end_x > $grid_x) {
$extra = $end_x - $grid_x;
$end_x = $grid_x;
$start_x = $start_x - $extra;
}
//same applies for the y axis
$start_y = ($y - $display_half) +1;
$end_y = $y + $other_half;
if ($start_y < 1) {
$start_y = 1;
$end_y = $display_rows;
} else
if ($end_y > $grid_y) {
$extra = $end_y - $grid_y;
$end_y = $grid_y;
$start_y = $start_y - $extra;
}
//showing the current parameters
echo "X $x - Y $y<br>";
?>
<table width="750" cellspacing="0" cellpadding="2" border="1">
<?php
//these 2 for loops represent the y and x axis
//using the data collected above the loops will properly display the grid
for ($Ty = $start_y; $Ty <= $end_y; $Ty++) {
//start new row
echo '<tr>';
for ($Tx = $start_x; $Tx <= $end_x; $Tx++) {
//show grid
DisplayGrid($Tx,$Ty);
}
echo '</tr>';
}
?>
</table>
<?php
This is the part of the code which don't shows the part below it{
$player=$_SESSION['player'];
$sfield="SELECT * from km_sfield where name='$player'";
$sfield2=mysql_query($sfield) or die(mysql_error());
$sfield3=mysql_fetch_array($sfield2) or die(mysql_error());
}
This doesn't shows up{
function DisplayGrid($gridx,$gridy) {
global $x, $y;
$bgcolor = 'background="http://conquerorsofsanvia.890m.com/img"';
//highlight current select grid coordinate
if ($gridx == $x && $gridy == $y) {
$bgcolor = 'background="http://conquerorsofsanvia.890m.com/img"';
}
if ($gridx == $sfield3[x] && $gridy == $sfield3[y]) {
$imgsrc = 'img src="http://conquerorsofsanvia.890m.com/img"';
}
echo "<td width=\"50\" height=\"50\" $bgcolor align=center valign=bottom><a style='line-height:1em;width:75%;height:75%;display:block;' href=\"grid.php?xcord=$gridx&ycord=$gridy\"></a><br><font size=1 color='blue'>($gridx,$gridy)</font></td>";
}
print "<table class='maintable'><tr class='headline'><td><center>Deploy Soldiers</center></td></tr>";
print "<tr class='mrw'><td>";
print "Each unit contains a squad of 100 units from the same class.<br>";
print "<form action='dplsoldiers.php' method='post'>";
print "<SELECT NAME='class'>";
print "<OPTION VALUE='Pikeman'>Pikeman";
print "<OPTION VALUE='Archers'>Archers";
print "<OPTION VALUE='Swordsman'>Swordsman";
print "<OPTION VALUE='Cavalry'>Cavalry";
print "</SELECT>";
print "<input type='submit' name='submit' value='submit'></form>";
print "</td></tr></table>";
}
?>