Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2003, 05:28 PM   PM User | #1
BobDoleX
New Coder

 
Join Date: Aug 2003
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
BobDoleX is an unknown quantity at this point
Lowering load time

I have a php script on my site that makes the site load really slow, i'm trying to see if there's anyway it could be faster. He's part of the script....

PHP Code:
<?php
if($tsr == "aboutdb"){$information "About the Series";}
elseif(
$tsr == "aboutstaff"){$information "About the Staff";}
elseif(
$tsr == "af"){$information "About Dragonball AF";}
elseif(
$tsr == "afterlife"){$information "The Afterlife";}
elseif(
$tsr == "aim"){$information "AIM Buddy Icons";}
elseif(
$tsr == "akira"){$information "Akira Toriyama";}
elseif(
$tsr == "androids"){$information "The Androids";}
elseif(
$tsr == "animated"){$information "Animated Gifs";}
else {
$information "content";}
?>
i have around 250 elseif statements, which is why i'm thinkin the site loads so slow. Is there anyway to do what i want, but faster like if i only use if statements or something?
BobDoleX is offline   Reply With Quote
Old 09-13-2003, 07:51 PM   PM User | #2
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
250 elseif statements?
That's close to unmaintainable. I doubt though they really slow down your page, unless they're called in loop or something.

But anyway, here's a different approach that cuts some lines:

PHP Code:
$titles = array(
"aboutdb" => "About the Series",
"aboutstaff" => "About the Staff"// etc.
);

if (isset(
$titles[$tsr])) {
$information $titles[$tsr];
} else {
$information "content";

All you need to do is populate the $titles array. You could even store the data in a file or in a database and fetch the $titles array contents from there.
__________________
De gustibus non est disputandum.
mordred is offline   Reply With Quote
Old 09-13-2003, 08:02 PM   PM User | #3
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
Looks like you should better use 'switch'

http://be.php.net/switch

or use an array or so. For instance, store these values like "About the Series" in an array and use an index instead of "aboutdb ". So use an integer instead of some cryprical stringvalue
Then you could have somenthin like

$array[$tsr]

If your array would look like
"0" => "About the Series"
"1" => "About the staff"

and $str = 1 then

$information = $array[$tsr]

would instantly set the rigth value for $information

<edit> posts crossed. mordreds code will be more transparent to maintain. </edit>
raf is offline   Reply With Quote
Old 09-13-2003, 08:06 PM   PM User | #4
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
I was already writing a reply about maintainability issues with your suggestion, raf....
__________________
De gustibus non est disputandum.
mordred is offline   Reply With Quote
Old 09-13-2003, 08:27 PM   PM User | #5
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
i know my own weaknesses. (Thats why most of my code is completely idiots-proof )

I kinda felt it wasn't the best way but i'm so used to working with databases and using primary key values, that i'm drawn to using indexes ...
raf is offline   Reply With Quote
Old 09-13-2003, 10:17 PM   PM User | #6
BobDoleX
New Coder

 
Join Date: Aug 2003
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
BobDoleX is an unknown quantity at this point
well how i get $tsr is i link all my pages "index.php?$tsr=stuff" and then, i just include "$tsr.html" so i really cant have $tsr as a number.

I know the site loads pretty fast in a highspeed connetion but i noticed it loaded a little slow with my 56k connection, and i have it catched too. It usually takes like 5-10 seconds to load it, but if it shouldn't take too long, maybe it might be my computer
BobDoleX is offline   Reply With Quote
Old 09-13-2003, 11:58 PM   PM User | #7
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
mordreds code should work.

I don't think the connectionspeed has an influence on the processingtime for your script. So it's probably something else (like loading images or so) that takes up the responsetime.
raf is offline   Reply With Quote
Old 09-14-2003, 12:00 AM   PM User | #8
Dawzz
New to the CF scene

 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Dawzz is an unknown quantity at this point
URL: http://tsr-corp.com/
Date Tested: Saturday, Sep 13, 17:53 EDT
Page Rating:
Rating Criteria: Standard
Total Page Size: 143168 bytes
Total Graphics: 115046 bytes - 27 images
Server Connections: 5


It's the graphics that is taking alot of the time
Don't know if the link will work for long or not but

http://r.netmechanic.com/toolbox/loa...&s=NetMechanic
Dawzz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:09 PM.


Advertisement
Log in to turn off these ads.