基本上我想做的就是在插入我需要显示的数据时使图像加载更快。图像永远不会改变,但相同代码中的文本会根据您正在查看的人而改变。我的代码循环遍历一组 25 个“技能”并获取每个技能的图像,并将用户信息显示在与图像相同的行上。我将如何缓存图像以使代码运行得更快并且不必不断加载图像?这是我的代码的样子:
function compare($user1) {
include "mysql.ws";
$user1 = str_replace(" ", "_", $user1);
$query = mysql_query("SELECT a.*, b.* FROM skills a JOIN activities b ON(a.playerName LIKE b.playerName) WHERE a.playerName LIKE '".fixName($user1)."' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($query);
$overall['lvl'] = 0;
$overall['xp'] = 0;
for ($i = 1; $i <=25; $i++){
$xptype = findType($i)."xp";
$overall["lvl"] += getLevelForXP($row[$xptype], $i);
$overall["xp"] += $row[$xptype];
}
//updateDonator($user1);
echo'<div class="OrnamentalBoxBg"><div class="OrnamentalBoxContent">
<div class="header">
<div class="left">
<span class="columnLevel">Level</span>
<span class="columnTotal">Total XP</span>
<span class="columnRank">Rank</span>
</div></div>
<div class="row" data-skill="combat" data-member="false">
<div class="left">
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table=0&rank='.findRank($user1,"0").'#'.findRank($user1,"0").'">
<span class="columnLevel">
'.dots($overall["lvl"]).'
</span>
</a>
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table=0&rank='.findRank($user1,"0").'#'.findRank($user1,"0").'">
<span class="columnTotal">
'.dots($overall["xp"]).'
</span>
</a>
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table=0&rank='.findRank($user1,"0").'#'.findRank($user1,"0").'">
<span class="columnRank">
'.findRank($user1,"0").'
</span>
</a>
</div>
<div class="middle">
<img src="http://sage-scape.com/hiscores/img/overall.png?2" alt="" title="">
<span class="statName"><span><span><span>Overall</span></span></span></span>
</div>
</div>
';
for ($i = 1; $i <=25; $i++){
$xptype = findType($i)."xp";
if($i == 25){
echo'
<div class="row last-row" data-skill="'.findSkill($i).'" data-member="'.member($i).'"> ';
} else {
echo'
<div class="row" data-skill="'.findSkill($i).'" data-member="'.member($i).'"> ';
}
if($row[$xptype] > 1)
echo'
<div class="left">
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table='.$i.'&rank='.findRank($user1,"$i").'#'.findRank($user1,"$i").'">
<span class="columnLevel">
'.getLevelForXP($row[$xptype],"$i").'
</span>
</a>
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table='.$i.'&rank='.findRank($user1,"$i").'#'.findRank($user1,"$i").'">
<span class="columnTotal">
'.dots($row["$xptype"],"$i").'
</span>
</a>
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table='.$i.'&rank='.findRank($user1,"$i").'#'.findRank($user1,"$i").'">
<span class="columnRank">
'.findRank($user1,"$i").'
</span>
</a>
</div>
<div class="middle">
<img src="http://sage-scape.com/hiscores/img/xp_'.fixName(findType($i)).'_total.png?2" alt="" title="" />
<span class="statName"><span><span><span>'.findType($i).'</span></span></span></span>
</div>
</div>
';
else
echo'
<div class="left">
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table='.$i.'&rank='.findRank($user1,"$i").'#'.findRank($user1,"$i").'">
<span class="columnLevel">
--
</span>
</a>
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table='.$i.'&rank='.findRank($user1,"$i").'#'.findRank($user1,"$i").'">
<span class="columnTotal">
--
</span>
</a>
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=0&table='.$i.'&rank='.findRank($user1,"$i").'#'.findRank($user1,"$i").'">
<span class="columnRank">
--
</span>
</a>
</div>
<div class="middle">
<img src="http://sage-scape.com/hiscores/img/xp_'.fixName(findType($i)).'_total.png?2" alt="" title="" />
<span class="statName"><span><span><span>'.findType($i).'</span></span></span></span>
</div>
</div>
';
}
echo'
</div></div>
<div class="OrnamentalBoxBottom"></div>
</div>
<div class="OrnamentalBox Width923 SegmentTwo" id="activityStats">
<div class="OrnamentalBoxTop"></div>
<div class="OrnamentalBoxTitle"><div class="Centre1"><div class="Centre2">
<h3 class="Gradient NoFlourish Centre"><span class="spacing" aria-hidden="true">Activity Stats</span>
<span class="G0">Activity Stats</span>
<span class="G1" aria-hidden="true">Activity Stats</span>
<span class="G2" aria-hidden="true">Activity Stats</span>
<span class="G3" aria-hidden="true">Activity Stats</span>
<span class="G4" aria-hidden="true">Activity Stats</span>
<span class="G5" aria-hidden="true">Activity Stats</span>
<span class="G6" aria-hidden="true">Activity Stats</span>
</h3></div></div></div>
<div class="FlatHeader playerNames">
<div class="left">
'.BBCode($user1).'</div>
</div>
<div class="playerAvatars">
<div class="left">
<img src="http://services.runescape.com/m=avatar-rs/'.$user1.'/chat.png?cachebust=1342804665991" alt="" title="">
</div>
</div>
<div class="OrnamentalBoxBg"><div class="OrnamentalBoxContent">
<div class="header">
<div class="left">
<span class="columnScore">Score</span>
<span class="columnRank">Rank</span>
</div>
</div>';
for ($i = 0; $i < 7; $i++){
$xptype = findActivityP($i);
if($i == 6){
echo'
<div class="row last-row">';
} else {
echo'
<div class="row">';
}
echo'
<div class="left">
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=1&table='.$i.'&rank='.findARank($user1,"$i").'#'.findARank($user1,"$i").'">
<span class="columnScore">
'.$row["$xptype"].'
</span>
</a>
<a href="http://sage-scape.com/hiscores/overall.ws?category_type=1&table='.$i.'&rank='.findARank($user1,"$i").'#'.findARank($user1,"$i").'">
<span class="columnRank">
'.findARank($user1,"$i").'
</span>
</a>
</div>
<div class="middle">
<img src="http://sage-scape.com/hiscores/img/'.findActivityP($i).'.png" alt="" title="">
<span class="statName"><span><span><span>'.findActivity($i).'</span></span></span></span>
</div>
</div>
';
}
}
有没有办法做到这一点?我有一个 MySQL 数据库,我可以做到这一点,但我不确定如何做到这一点。有人可以告诉我怎么做吗?