OK. Im working on a small RPG for a few friends, and I ran into an issue...
I have several tables set up in the mysQL db, one of which is used for the users' info, and another for map info. Each 'piece' of the map has an entry in the DB, which i created with this:
$i = -101;
while($i < 101){
$n = -101;
while($n < 101){
$change = mysql_query("INSERT INTO `map` ( `$place` , `x` , `y` , `src` )
VALUES ( '$field', '$n', '$i', '$src' )", $link_id);
$n++;
echo"($n,$i)<br>";
}
$i++;
}
I use another script similar to this to add random patches of different terrain, such as water or rocks... etc
Each piece, and each player has a x and y value, which is stored. This was easy.
The players begin the game with in a random location, in the lowest level map...
The hard part is actually loading the map. I made a table(html) 7cells by 7 cell, and in each cell i called this function:
function maptile($x, $y, $link_id){
$gettile = mysql_query("SELECT * FROM `map` WHERE `x`='$x' AND `y`='$y' LIMIT 1 ", $link_id);
$tilearray = mysql_fetch_array($gettile);
$src = $tilearray["src"];
$gettileplayer = mysql_query("SELECT * FROM `location` WHERE `last_x`='$x' AND `last_y`='$y'", $link_id);
$tilearrayplayer = mysql_fetch_array($gettileplayer);
$playersrc = $tilearrayplayer["name"];
if(isset($playersrc)){
$image = "../images/player.gif";
$dbinfo = mysql_query("SELECT * FROM `creature` WHERE `name`='$playersrc'", $link_id);
$infoArray = mysql_fetch_array($dbinfo);
getCreature($playersrc, $link_id);
$additions .= "onmouseover=\"changePlayer('$playersrc','','','','');MM_showHideLayers('info_$playersrc','','show')\" onmouseout=\"changePlayer(0,0,0,0,0);MM_showHideLayers('info_$playersrc','','hide')\"";
echo"<table background=\"$src\" height=\"40\" width=\"40\"><tr><td><a href=\"javascript:;\"><img border=\"0\" height=\"40\" width=\"40\" src=\"$image\" $additions></a></td></tr></table>";
echo"<div id='info_$playersrc' style='position:absolute; left:0px; top:45px; width:315px; height:29px; z-index:1; visibility: hidden;'><table width='100%' height='0' border='0' cellpadding='1' cellspacing='0' class='info'><tr align='left' valign='middle' bgcolor='#333333'> <td height='0'><div align='left'><font color='#FFFFFF' size='1' face='Verdana, Arial, Helvetica, sans-serif'>HP: </font></div></td><td height='0' align='left' valign='middle' class='info'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>";
echo healthbar('9', '65', $playersrc, $link_id);
echo"</font></td><td width='22' height='0'><font color='#FFFFFF' size='1' face='Verdana, Arial, Helvetica, sans-serif'>AP:</font></td>";
echo"<td width='163' height='0' align='left' valign='middle' class='info'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>";
echo attackbar('9', '65', $playersrc, $link_id);
echo "</font></td>
</tr><tr align='left' valign='middle' bgcolor='#333333'>
<td height='0'><font color='#FFFFFF' size='1' face='Verdana, Arial, Helvetica, sans-serif'>str:</font></td>
<td height='0' align='left' valign='middle' class='info'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>$strength $str</font></td>
<td width='22' height='20'><font color='#FFFFFF' size='1' face='Verdana, Arial, Helvetica, sans-serif'>def:
</font></td><td width='163' height='0' align='left' valign='middle' class='info'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>$defense $def'</font></td>
</tr></table></div>";
}elseif($playersrc == ""){
$additions = "alt=\"($x,$y)\"";
echo"<table background=\"$src\" height=\"40\" width=\"40\"><tr><td><a href=\"javascript:;\"><img border=\"0\" height=\"40\" width=\"40\" src=\"../images/clear.gif\" $additions></a></td></tr></table>";
}
}
Which loads the tiles. If another player has a location on a given tile, it displays an image for the player, and a mouseover showing their stats. The problem is, that calling this function 49 times seems to cause a really long wait. Ive tried scaling down the function, and stripping it down, but it doesnt do much. If anyone has any clue as to what I could do to make this mvoe a little faster could help. Typically the page takes 15- 20seconds to load.😕