The operators . and + have the same precedence, so without the parens I added you would first concatenate the two variables as strings and then add 1 to the result (which might give some unexpected results if the resulting concatenation before that is not a number).
$eastcount = $eastcount + $celspercol[0];
} # <---- What is this ending?
$northcount = $northcount + $celsperrow[0];
What is that brace ending? Could it be an if clause that is not being executed at all?
SpectreReturns
09-15-2005, 08:47 PM
Here's what you can do for us to help you:
Provide the whole script, tell us what it should be doing, show us where you think the error is, give us any errors you recieve, and before posting try to figure it out yourself.
From what you've provided, we're able to find out nothing, since you have included syntax part of what you did not post, thus we can't help you.
[How to debug]
Put an echo inside every control structure you use to check if it is running. Echo all variables which these control structures require if they don't run. Before and after changing a variable, echo it, so you can see if that's where it's dying.
DARTHTAMPON
09-15-2005, 10:15 PM
the script
<?php
class gridstats
{
var $north; #vertical low number
var $south; #vertical high number
var $east; #horizontal low number
var $west; #horizontal high number
var $nors; #vertical direction
var $eorw; #horizontal direction
var $celsperrow = array(); #array that holds how many lands are in each row.
var $celspercol = array(); #array that holds how many lands are in each column.
var $cordsarray = array(); # array that holds the cords for each class
# requires: $cords: array that holds 6 pieces of date with coordinates
# $lands: amount of lands in each cell
# modifies: nothing
# effects : creats the data used in the class
function gridstats ($cords, $lands)
{
$this->north = $cords[0];
$this->south = $cords[1];
$this->east = $cords[3];
$this->west = $cords[4];
$this->nors = $cords[2];
$this->eorw = $cords[5];
$totalV = $this->south - $this->north; #total number of cells vertical
$totalH = $this->west - $this->east; #total number of cells horizontal
#################### get number of lands in each row ##########################################################
$numrows = (int)($totalV / $lands); #number of rows allowed
for ($x = 0; $x < $numrows; $x++)
{
$this->celsperrow[$x] = $this->celsperrow[$x-1] + ($lands); #build array that holds cells per grid info
if ($x == $numrows - 1)
{
$this->celsperrow[$x] = ($this->celsperrow[$x-1] + $lands) + (($this->south - $this->north) - ($lands * $numrows));
}
}
#################### get number of lands in each column ######################################################
$numrows = (int)($totalH / $lands); #number of rows allowed
for ($x = 0; $x < $numrows; $x++)
{
$this->celspercol[$x] = $this->celspercol[$x-1] + $lands; #build array that holds cells per grid info
if ($x == $numrows - 1)
{
$this->celspercol[$x] = ($this->celspercol[$x-1] + $lands) + (($this->south - $this->north) - ($lands * $numrows));
}
}
$northcount = 0; #current number north is on
#################### create cords array ######################################################
for ($x = 0; $x < ((int)($totalV / $lands)); $x++)
{
if ($x == 0)
$northcount = $this->north;
for ($y = 0; $y < ((int)($totalH / $lands)); $y++)
{
if ($y == 0)
$eastcount = $this->east;
$temp = $this->north + $this->celsperrow[$x];
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y]."<br>?cords=";
if ($x != 0)
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].($northcount + 1);
else
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].$northcount;
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].",$temp,$this->nors,";
if ($y != 0)
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].($eastcount + 1);
else
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].$eastcount;
$temp = $this->east + $this->celspercol[$y];
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].",$temp,$this->eorw";
$eastcount = $eastcount + $this->celspercol[0];
}
$northcount = $northcount + $this->celsperrow[0];
echo "xxx".$this->cordsarray[$x][$y];
print_r($this->cordsarray);
}
}
}
$test = array(301,350,'n',301,350,'e');
$temp1 = new gridstats($test, 10);
?>
In the parts below I will be using thsi call
$temp = new gridstats ([0][50]['n'][0][50]['w'], 10)
what it does
class gridstats
{
var $north; #vertical low number 0
var $south; #vertical high number 50
var $east; #horizontal low number 0
var $west; #horizontal high number 50
var $nors; #vertical direction n
var $eorw; #horizontal direction w
var $celsperrow = array(); #array that holds how many lands are in each row.
var $celspercol = array(); #array that holds how many lands are in each column.
var $cordsarray = array(); # array that holds the cords for each class
create a class and initilize above variables. What they are is commented be side it.
# requires: $cords: array that holds 6 pieces of date with coordinates
# $lands: amount of lands in each cell
# modifies: nothing
# effects : creats the data used in the class
function gridstats ($cords, $lands)
{
This function is the constructor for the class It recieves 2 variables. $cords[5] = an array that holds information about the size of the grid. $lands is an int that will tell the construct how many lands are in each row and column.
$this->north = $cords[0]; #low number vertical 0
$this->south = $cords[1]; #high number vertical 50
$this->east = $cords[3]; #low number horazontal 0
$this->west = $cords[4]; #high number horazontal 50
$this->nors = $cords[2]; #vertical n or s north or south n
$this->eorw = $cords[5]; #horizontal e or w east or west w
$totalV = $this->south - $this->north; #total number of cells vertical
$totalH = $this->west - $this->east; #total number of cells horizontal
This section contains variable sets in the class.
#################### get number of lands in each row ##########################################################
$numrows = (int)($totalV / $lands); #number of rows allowed #$numrows 5 = int(5.1 = 51/10)
for ($x = 0; $x < $numrows; $x++) #count 0, 1, 2, 3, 4
{
$this->celsperrow[$x] = $this->celsperrow[$x-1] + ($lands); #build array that holds lands per grid info
if ($x == $numrows - 1) #if $numrows does not mod 1 to 0, will include additional lands
{
$this->celsperrow[$x] = ($this->celsperrow[$x-1] + $lands) + (($this->south - $this->north) - ($lands * $numrows));
}
}
#################### get number of lands in each column ######################################################
$numrows = (int)($totalH / $lands); #number of rows allowed
for ($x = 0; $x < $numrows; $x++)#count 0, 1, 2, 3, 4
{
$this->celspercol[$x] = $this->celspercol[$x-1] + $lands; #build array that holds cells per grid info
if ($x == $numrows - 1)#if $numrows does not mod 1 to 0, will include additional lands
{
$this->celspercol[$x] = ($this->celspercol[$x-1] + $lands) + (($this->south - $this->north) - ($lands * $numrows));
}
}
this will create an array that looks like this
$this->celsperrow[5] (10 20 30 40 50)
$this->celspercol[5] (10 20 30 40 50)
now this is where my problem is
$northcount = 0; #current number north is on
#################### create cords array ######################################################
for ($x = 0; $x < ((int)($totalV / $lands)); $x++) #counts 0,1,2,3,4,5
{
if ($x == 0)
$northcount = $this->north;
for ($y = 0; $y < ((int)($totalH / $lands)); $y++) #counts 0,1,2,3,4,5
{
if ($y == 0)
$eastcount = $this->east; #50
$temp = $this->north + $this->celsperrow[$x]; #creates $cords[1] # 0+10
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y]."<br>?cords="; #$ar[0][0] = ?cords=
if ($x != 0) # add 1 to $cords[0]
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].($northcount + 1);#$ar[0][0] = ?cords=1
else #doesn't
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].$northcount;#$ar[0][0] = ?cords=0
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].",$temp,$this->nors,"; #$ar[0][0] = ?cords=0,10,n
if ($y != 0) # add 1 to $cords[4] connects to array
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].($eastcount + 1);#$ar[0][0] = ?cords=0,10,n,0
else # doesn't
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].$eastcount; #$ar[0][0] = ?cords=0,10,n,1
$temp = $this->east + $this->celspercol[$y]; #creates $cords[4]
$this->cordsarray[$x][$y] = $this->cordsarray[$x][$y].",$temp,$this->eorw"; #$ar[0][0] = ?cords=0,10,n,0,10,w
$eastcount = $eastcount + $this->celspercol[0]; #$eastcount = 0+10
}
$northcount = $northcount + $this->celsperrow[0]; #northcount = 0+10
echo "xxx".$this->cordsarray[$x][$y]; #print to screen what the above varaible shold look like. Prints nothing
print_r($this->cordsarray); #same as above does nothing.
}
Ok so there the code spill out> I apolagize about the previous posts. I do not mean to make it look like I want it done for me but more to figure out what I am doing wrong.
I originaly built the array values with echos and everything worked out fine. The problems started when I replaced the echo's with the array variable.
The logice for getting the values is correct. Im just doing something wrong with concatinating everything and storing it into the array.
No errors are on the page or when I run it using ssh. the "xxx" on the echo prints out correctly telling me that the values are running corectly. I just cant get anything into the array.
any help????
webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved.