By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Problem When Generating HTML

P: n/a
I am having troubles with my script. It is supposed to generate a
"map" from a serialized array stored in a database. However, it is not
generating any html. I know the data is being retrieved from the
database and being unserialized properly as I've tested that. It seems
to not go through the loop.

/**
* function drawMap( $startx, $starty, $p1, $p2, $p3 )
* Generates html for output.
*/
function drawMap( $startx, $starty, $p1, $p2, $p3 )
{
$sql = "SELECT * FROM `cp_citymap` WHERE `p1` = '$p1' AND `p2` =
'$p2' AND `p3` = '$p3'";
$query = $this->database->query( $sql );
$num = $this->database->count_rows( $query );

if( $num != 1 )
{
$this->error = "Could not find City Map data.";
return false;
}

$row = $this->database->get_row( $query );

$mapArray = unserialize( $row['blocks'] );

$x = $startx;
$y = $starty;
$maxx = $x - 11;
$maxy = $y + 10;

while( $x < $maxx )
{
$this->outputHTML .= "<span class=\"cityMapBlock\"><a href=\"#\"
title=\"" . $mapArray[$x][$y]['type'] . "\">" . $mapArray[$x][$y]
['type'] . "</a></span>";

if( $mapArray[$x][$y] == $maxy )
{
$this->outputHTML .= "</br>";
$y = $maxy - 10;
$x--;
}
}

return true;
}

Any help at all would be appreciated greatly, and I'll give you a
million internets.

May 2 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On May 2, 6:11 pm, dawnerd <dawn...@gmail.comwrote:
I am having troubles with my script. It is supposed to generate a
"map" from a serialized array stored in a database. However, it is not
generating any html. I know the data is being retrieved from the
database and being unserialized properly as I've tested that. It seems
to not go through the loop.

/**
* function drawMap( $startx, $starty, $p1, $p2, $p3 )
* Generates html for output.
*/
function drawMap( $startx, $starty, $p1, $p2, $p3 )
{
$sql = "SELECT * FROM `cp_citymap` WHERE `p1` = '$p1' AND `p2` =
'$p2' AND `p3` = '$p3'";
$query = $this->database->query( $sql );
$num = $this->database->count_rows( $query );

if( $num != 1 )
{
$this->error = "Could not find City Map data.";
return false;
}

$row = $this->database->get_row( $query );

$mapArray = unserialize( $row['blocks'] );

$x = $startx;
$y = $starty;
$maxx = $x - 11;
$maxy = $y + 10;

while( $x < $maxx )
{
$this->outputHTML .= "<span class=\"cityMapBlock\"><a href=\"#\"
title=\"" . $mapArray[$x][$y]['type'] . "\">" . $mapArray[$x][$y]
['type'] . "</a></span>";

if( $mapArray[$x][$y] == $maxy )
{
$this->outputHTML .= "</br>";
$y = $maxy - 10;
$x--;
}
}

return true;
}

Any help at all would be appreciated greatly, and I'll give you a
million internets.
You have this:

$x = $startx;

Then you have:

$maxx = $x - 11;

So, right from the start, $maxx is less than $x. As such, the
condition in your while loop ($x < $maxx) is never true.

May 2 '07 #2

P: n/a
On May 2, 3:11 pm, dawnerd <dawn...@gmail.comwrote:
I am having troubles with my script. It is supposed to generate a
"map" from a serialized array stored in a database. However, it is not
generating any html. I know the data is being retrieved from the
database and being unserialized properly as I've tested that. It seems
to not go through the loop.

/**
* function drawMap( $startx, $starty, $p1, $p2, $p3 )
* Generates html for output.
*/
function drawMap( $startx, $starty, $p1, $p2, $p3 )
{
$sql = "SELECT * FROM `cp_citymap` WHERE `p1` = '$p1' AND `p2` =
'$p2' AND `p3` = '$p3'";
$query = $this->database->query( $sql );
$num = $this->database->count_rows( $query );

if( $num != 1 )
{
$this->error = "Could not find City Map data.";
return false;
}

$row = $this->database->get_row( $query );

$mapArray = unserialize( $row['blocks'] );

$x = $startx;
$y = $starty;
$maxx = $x - 11;
$maxy = $y + 10;

while( $x < $maxx )
{
$this->outputHTML .= "<span class=\"cityMapBlock\"><a href=\"#\"
title=\"" . $mapArray[$x][$y]['type'] . "\">" . $mapArray[$x][$y]
['type'] . "</a></span>";

if( $mapArray[$x][$y] == $maxy )
{
$this->outputHTML .= "</br>";
$y = $maxy - 10;
$x--;
}
}

return true;
}

Any help at all would be appreciated greatly, and I'll give you a
million internets.
I just realized that I pasted the wrong while function. It is still
the same, only I meant for it to be:
while( $x $maxx )

Since $maxx will be a number less that $x. It starts reading the data
from the top left corner of the "graph" However, I now get a 500
error. The error_log says: Allowed memory size of 8388608 bytes
exhausted (tried to allocate 10 bytes)

I've never encountered this in my PHP adventures.

May 2 '07 #3

P: n/a
On Wed, 02 May 2007 15:22:46 -0700, dawnerd wrote:
On May 2, 3:11 pm, dawnerd <dawn...@gmail.comwrote:
>I am having troubles with my script. It is supposed to generate a
"map" from a serialized array stored in a database. However, it is not
generating any html. I know the data is being retrieved from the
database and being unserialized properly as I've tested that. It seems
to not go through the loop.
> while( $x $maxx )
{
$this->outputHTML .= "<span class=\"cityMapBlock\"><a href=\"#\"
title=\"" . $mapArray[$x][$y]['type'] . "\">" . $mapArray[$x][$y]
['type'] . "</a></span>";

if( $mapArray[$x][$y] == $maxy )
{
$this->outputHTML .= "</br>";
$y = $maxy - 10;
$x--;
}
}

return true;
You have included the $x decrement in the if-clause, so unless you get
there right away you keep adding the same line to your $html over and
over, which, as the error told you, ends as soon as the variable has eaten
all of your available memory (default is 8 megs I believe).
Outside the if {...} $x should get a new value.

HTH

Sh.
May 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.