Page 1 of 1

Multi Query Map

Posted: Sat Jan 09, 2010 10:48 pm
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>";
 
?>

Re: Multi Query Map

Posted: Sun Jan 10, 2010 12:04 pm
by fallenangel820
Does no one have any idea?

Re: Multi Query Map

Posted: Tue Jan 12, 2010 6:52 pm
by fallenangel820
bump

Re: Multi Query Map

Posted: Thu Jan 14, 2010 7:38 pm
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>