Multi Query Map

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fallenangel820
Forum Newbie
Posts: 4
Joined: Sat Jan 09, 2010 10:38 pm

Multi Query Map

Post by fallenangel820 »

Good Evening Ladies and Gentlemen.

I have a question and am seeking some assistance if possible. I have 2 tables in my database one called map the other is users. What I'm trying to do is generate a map that is 15x15 that has the avatar associated with the user appear in the center. I'm confused on how to get the avatar in the middle of the table along with pulling from 2 tables. I need the x,y coords and the avatar from the users table, and I need the x,y coords and the tile (image) from the map table.

Here is what I have so far. Which generates the 15x15 map.

Code: Select all

<?php
include ("database.php");
 
$result = mysql_query("SELECT xloc, yloc FROM users where user='fallenangel820'");
 
$xloc = $result['xloc'];
$yloc = $result['yloc'];
$xstart = $xloc - 3;
$ystart = $yloc - 3;
 
echo "<table cellpadding=0 cellspacing=0>";
for ($x=$xstart; $x<=$xstart + 14; $x++)
    {
    echo "<tr>";
    for ($y=$ystart; $y<=$ystart + 14; $y++)
        {
        echo "<td><img src=\"/images/map/center.gif\"></td>";
        }
    echo "</tr><br />";
    }
echo "</table>";
 
?>
fallenangel820
Forum Newbie
Posts: 4
Joined: Sat Jan 09, 2010 10:38 pm

Re: Multi Query Map

Post by fallenangel820 »

Does no one have any idea?
fallenangel820
Forum Newbie
Posts: 4
Joined: Sat Jan 09, 2010 10:38 pm

Re: Multi Query Map

Post by fallenangel820 »

bump
fallenangel820
Forum Newbie
Posts: 4
Joined: Sat Jan 09, 2010 10:38 pm

Re: Multi Query Map

Post by fallenangel820 »

I found my own answer and figured it out. Just figured I would post it in case somebody else wants to know how to do something similar.

Code: Select all

<?php
include ("database.php");
 
$query1 = mysql_query("SELECT xloc, yloc, avatar FROM users where user='fallenangel820'");
$result1 = mysql_fetch_array($query1);
 
$xloc = $result1['xloc'];
$yloc = $result1['yloc'];
$player_avatar = $result1['avatar'];
$xstart = $xloc - 7;
$ystart = $yloc - 7;
 
 
$range = 7;
$query2 = mysql_query("SELECT * from map WHERE ((xmap >= $xloc-$range) AND (xmap <= $xloc+$range)) AND ((ymap >= $yloc-$range) AND (ymap <= $yloc+$range))");
while( $result2 = mysql_fetch_array($query2) ) {
    $xmap = $result2['xmap'];
    $ymap = $result2['ymap'];
    $tile = $result2['tile'];
    $map[$ymap][$xmap] = $tile;
}
 
?>
 
<html>
<head>
<!--<link rel="stylesheet" type="text/css" href="/buildmap.css" />-->
</head>
<body>
 
Your current location is <?php echo $xloc . "," . $yloc; ?>.<br />
<br /><br /><hr />
<?php
echo "<table cellpadding=0 cellspacing=0><br />";
foreach ($map as $map_y => $v) {
    echo "<tr>";
        foreach($v as $map_x => $map_tile) {
 
            if( ($map_y == $yloc) && ($map_x == $xloc) ) {
                echo "<td width='32' height='32' background='" . $map_tile. "'><img src='/images/avs/" . $player_avatar . "'/></td>";           
            } else {
                echo "<td width='32' height='32' background='" . $map_tile. "'></td>";
            }
        }
    echo "</tr>";
}
echo "</table>";
 
 
?>
</body>
</html>
Post Reply