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
NewSpecies
Forum Newbie
Posts: 3 Joined: Sat Jan 18, 2003 9:06 am
Post
by NewSpecies » Sat Jan 18, 2003 9:06 am
Alright, I have tried many tests on my page to find out why this page was generating in around 1.1 sec. I narraowed it down to this one call thats made on a function that echo's a template for a "monster" on my site. Let me give you a little info about my site. I play a game called Ragnarok Online and the whole purpose of this game is to distroy monsters and get higher levels [Diablo Type Game]. Now each monster has it's own specific stats like hp atk def etc ... but there is around 19 diferent stats. Quering them from the database takes about 3E-005, but what takes up the most time is executing this one echo.
echo '<table width="500" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td><img src="Images/GUI/Monster/Monster_Top_Left.gif" width="3" height="16" alt=""></td><td width="494" height="16" class="Monster_Top_Center"><img src="Images/GUI/Monster/Monster_Spacer.gif" width="494" height="16" alt=""></td><td width="3" height="16"><img src="Images/GUI/Monster/Monster_Top_Right.gif" width="3" height="16" alt=""></td></tr><tr><td class="Monster_Mid_Left"> </td><td><table width="494" border="0" cellspacing="0" cellpadding="0"><tr bgcolor="E5E5E5"><td width="194" align="center">' . $font . '<b>Name</b>: ' . $display_name . $font_end . '</td><td width="150" valign="top">' . $font . '<b>Level</b>: ' . $display_level . $font_end . '</td><td width="150" valign="top">' . $font . '<b>Aggressive</b>: ' . $display_aggressive . $font_end . '</td></tr><tr><td width="194" rowspan="7" align="center" valign="middle" bgcolor="EEEEEE"><img src="' . $display_pic . '" alt=""></td><td width="150" valign="top" bgcolor="EEEEEE">' . $font . '<b>Def</b>: ' . $display_def . $font_end . '</td><td valign="top" bgcolor="EEEEEE">' . $font . '<b>Looter</b>: ' . $display_looter . $font_end . '</td></tr><tr><td width="150" valign="top" bgcolor="E5E5E5">' . $font . '<b>MDef</b>: ' . $display_mdef . $font_end . '</td><td valign="top" bgcolor="E5E5E5">' . $font . '<b>Supporter</b>: ' . $display_supporter . $font_end . '<td></tr><tr><td width="150" valign="top" bgcolor="EEEEEE">' . $font . '<b>HP</b>: ' . $display_hp . $font_end . '</td><td valign="top" bgcolor="EEEEEE">' . $font . '<b>Cast Detect</b>: ' . $display_castdetect . $font_end . '</td></tr><tr><td width="150" valign="top" bgcolor="E5E5E5">' . $font . '<b>Atk</b>: ' . $display_atk . $font_end . '</td><td valign="top" bgcolor="E5E5E5">' . $font . '<b>Element</b>: ' . $display_element . $font_end . '</td></tr><tr><td width="150" valign="top" bgcolor="EEEEEE">' . $font . '<b>Base Exp</b>: ' . $display_base . $font_end . '</td><td valign="top" bgcolor="EEEEEE">' . $font . '<b>Type</b>: ' . $display_type . $font_end . '</td></tr><tr><td width="150" valign="top" bgcolor="E5E5E5">' . $font . '<b>Job Exp</b>: ' . $display_job . $font_end . '</td><td valign="top" bgcolor="E5E5E5">' . $font . '<b>Size</b>: ' . $display_size . $font_end . '</td></tr><tr><td colspan="2" valign="top"><table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="EEEEEE">' . $font . '<b>Drops</b>: ' . $display_drops . $font_end . '</td></tr><tr><td bgcolor="EEEEEE">' . $font . '<b>Locations</b>: ' . $display_location . $font_end . '</td></tr></table></td></tr><tr bgcolor="E5E5E5"><td colspan="3" valign="top">' . $font . '<b>Card</b>: ' . $display_card . $font_end . '</td></tr></table></td><td class="Monster_Mid_Right"> </td></tr><tr><td width="3" height="16"><img src="Images/GUI/Monster/Monster_Bot_Left.gif" width="3" height="16" alt=""></td><td width="494" height="16" class="Monster_Bot_Center"><img src="Images/GUI/Monster/Monster_Spacer.gif" width="494" height="16" alt=""></td><td width="3" height="16"><img src="Images/GUI/Monster/Monster_Bot_Right.gif" width="3" height="16" alt=""></td></tr></table><br>';
is a fairly large echo, but I don't see why it would echo in .45 sec [first] and around .18 [anytime else]. If you have any idea please post
http://newspecies.homeip.net/Geffen/Ind ... ry=monster
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 18, 2003 9:48 am
There's no need for conatenating the strings via $s1.$s2.
echo is capable of taking multiple paramters and will print each of them.
You may enter and leave php-blocks freely without too much harm to performance (maybe the first time the page is called, next time the optimizer-cache takes care of it)
Code: Select all
<?php // code to retrieve data ?>
?><table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<img src="Images/GUI/Monster/Monster_Top_Left.gif" width="3" height="16" alt="">
</td>
<td width="494" height="16" class="Monster_Top_Center">
<img src="Images/GUI/Monster/Monster_Spacer.gif" width="494" height="16" alt="">
</td>
<td width="3" height="16">
<img src="Images/GUI/Monster/Monster_Top_Right.gif" width="3" height="16" alt="">
</td>
</tr>
<tr>
<td class="Monster_Mid_Left"> </td>
<td>
<table width="494" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="E5E5E5">
<td width="194" align="center">
<?php echo $font; ?>
<b>Name</b>: <?php echo $display_name, $font_end; ?>
</td>
<td width="150" valign="top">
<?php echo $font; ?>
<b>Level</b>
<?php echo $display_level, $font_end; ?>
</td>
[...]make the code much more readable.
Also consider using css to set properties of repeating elements only once, e.g. the font-property
Code: Select all
<head>
<style type="text/css">
td { font-size: large; font-family:fantasy; font-variant:small-caps }
</style>
NewSpecies
Forum Newbie
Posts: 3 Joined: Sat Jan 18, 2003 9:06 am
Post
by NewSpecies » Sat Jan 18, 2003 10:04 am
Yeah I use the css on the page
$font = "<font class='font'>";
$font_end = "</font>";
It's less messy and make it easier to edit
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 18, 2003 10:07 am
but takes more space, because you're using it on each element.
NewSpecies
Forum Newbie
Posts: 3 Joined: Sat Jan 18, 2003 9:06 am
Post
by NewSpecies » Sat Jan 18, 2003 10:17 am
That is true, but I can't do it any other way ... the text inside the table can only be changed within the cell
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 18, 2003 10:47 am
??
if you put your stylesheet in the <HEAD>-section it can change the properties of the cells. Not the content but the properties. That's what css is about
Code: Select all
<html>
<head>
<style type="text/css">
td { color: red }
td.notRed { color: green }
td b { text-decoration: underline }
</style>
</head>
<body>
<table border="1">
<tr>
<td>a</td>
<td class="notRed">b</td>
</tr>
<tr>
<td class="notRed">c</td>
<td>
<b>d</b>
</td>
</tr>
</table>
<b>bold but no underline</b>
</body>
</html>