Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 11th, 2006, 11:35 PM
gilbert.havlik@gmail.com
Guest
 
Posts: n/a
Default Please help with logical or syntactical problem!

Greetings!

Please be so kind and take a few minutes, I believe any mind other than
mine can solve this. I am writing a game. As you wander through the
gameworld, you may come upon signs. I have a DB where the signs are
listed, with "longitude" and "latitude". Anytime someone takes a step,
I want to show a grid where any square can be reached within 3 steps.
And if there's a sign in one grid, I want to show it, so the player can
walk directly to it.
In my test environment I have three signs located very close and around
to 100|50. The routine I wrote below works. But it only gives me the
last of the three signs. And I just can't tell if it's a logical
problem with my two loops and the foreach, or if there's a hook with
PHP itself.

So why does it only show me the last of the three signs????
Also, how can I make this with POST?
And I know this is messy, how could I make it faster?

I am grateful for any pointer!

Helpless regards, Gilbert.

PS: $lire is for x, $raru is for y

<pre>
$signr = $db->get_results("SELECT text,longitude,latitude FROM signs
WHERE longitude>$lire-4 and longitude<$lire+4 and latitude>$raru-4 and
latitude<$raru+4",ARRAY_A);

for ($j = 3 ; $j <= 9 ; $j++) {
for ($i = 3 ; $i <= 9 ; $i++) {
$cps[$i][$j] = "<td width=30 height=30 align=center valign=center><a
href='main.php?dir=$i$j'><img src='images/";
$icon = "gravel.gif";
if (is_array($signr)) {
reset($signr);
foreach($signr as $check) {
$x = $lire+$i-6;
$y = $raru+$j-6;
if ($check['longitude'] == $x && $check['latitude'] == $y ) {
$icon = "scroll.gif";
}
else $icon = "gravel.gif";
}
}
$cps[$i][$j] .= $icon;
$cps[$i][$j] .= "' style='border:2px outset black'
border=0></a></td>";
}
}
// $cps[6][6] = "<td></td>";
$compass = "<form action='main.php' method='POST'>";
$compass .="<table cellspacing=0 cellpadding=0
background='images/xmap.jpg'>";
$compass .= "<tr><td></td><td></td><td></td> ".$cps[6][3]."
<td></td><td></td><td></td></tr>\n";
$compass .= "<tr><td></td><td></td>
".$cps[5][4].$cps[6][4].$cps[7][4]."<td></td><td></td></tr>\n";
$compass .= "<tr><td></td>
".$cps[4][5].$cps[5][5].$cps[6][5].$cps[7][5].$cps[8][5]."<td></td></tr>\n";
$compass .=
"<tr>".$cps[3][6].$cps[4][6].$cps[5][6].$cps[6][6].$cps[7][6].$cps[8][6].$cps[9][6]."</tr>\n";
$compass .= "<tr><td></td>
".$cps[4][7].$cps[5][7].$cps[6][7].$cps[7][7].$cps[8][7]."<td></td></tr>\n";
$compass .= "<tr><td></td><td></td>
".$cps[5][8].$cps[6][8].$cps[7][8]."<td></td><td></td></tr>\n";
$compass .= "<tr><td></td><td></td><td></td> ".
$cps[6][9]."<td></td><td></td><td></td></tr>\n";
$compass .= "</table></form>";
unset($cps);
</pre>

  #2  
Old May 13th, 2006, 01:55 PM
Gilbert
Guest
 
Posts: n/a
Default Re: Please help with logical or syntactical problem!

I wrote that part again. This time the $cps is premade, and I only
foreach $signr and replace the $cps where necessary. Learning by
doing...
Thanks anyway to anyone who read it.
Greets, Gilbert.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.