[PHP] Multiple pages or Multiple If's?

C++, C#, Java, PHP, ect...
Post Reply
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

[PHP] Multiple pages or Multiple If's?

Post by vitinho444 »

Hey guys, I'm doing a job test for a company, they asked me to build their website and a mobile App.

I'm starting on the website and let's say it's like Indie-Resource Resource website, You got a bunch of "items" that you can search and check etc.

The question is, In my "items" page, I have several if($_GET) that will present a different content.

And the whole file is like 400 lines, so is it better to separate in multiple files like this:

Code: Select all

if(isset($_GET["id"]))
include "showproductbyid.php";
else if(isset($_GET["mypproducts"]))
include "showmyproducts.php";
else if(....)
....
Or just have the 400 lines there being loaded everytime the user enters new GET?
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Xaos
Posts: 946
Joined: Wed Jan 11, 2012 4:01 am

Re: [PHP] Multiple pages or Multiple If's?

Post by Xaos »

Probably multiple files, because if one goes wrong in a huge if-else if, it will bring down the whole thing. If you separate it, it will only bring down that page. Better for troubleshooting later and for functionality of the web site.
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: [PHP] Multiple pages or Multiple If's?

Post by vitinho444 »

Xaos wrote:Probably multiple files, because if one goes wrong in a huge if-else if, it will bring down the whole thing. If you separate it, it will only bring down that page. Better for troubleshooting later and for functionality of the web site.
Well yeah, the if-else if is not that big, but the code within is, and may be bigger in the end. What I want to achieve is low page load times first, then troubleshooting performance :P

Thank you for your reply ;)
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: [PHP] Multiple pages or Multiple If's?

Post by hallsofvallhalla »

wont have a noticeable effect on performance and you still have multiple include files to hold the functions and just call the function

some psuedo code

index.html

Code: Select all

<script type="javascript" src="pageFunctions.js>

<body>
<div id="showText"></div>
<div id="showButtons></div>
<input type="button" onclick="showText()" value="Choose" />
<input type="button" onclick="showButton()" value="Choose" />


</body>
pagefunctions.js

Code: Select all


function showText()
{
document.getElementById("showText").innerHTML = "Hey this is text!.";
}

function showButton()
{
document.getElementById("showText").innerHTML = "<input type='button'  value='I ama button!' />";
}

User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: [PHP] Multiple pages or Multiple If's?

Post by vitinho444 »

I get what you are saying halls, but I think for this that's not the best approach, since I have to do more than just "edit" the innerHTML (change the content). And i would still have to have those lines on the javascript functions :/

But i appreciate the help ;)
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: [PHP] Multiple pages or Multiple If's?

Post by Jackolantern »

This is the kind of stuff MVC was made for :P

But as far as the question goes, 400 lines is nothing. The Zend Engine can blast through 400 lines of IF/ELSE statements in under 1ms. PHP may be slow, but it isn't that slow ;)
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: [PHP] Multiple pages or Multiple If's?

Post by hallsofvallhalla »

yeah i definitely would not worry abut line numbers. When you put jquery, jquery-UI, bootstrap, and all the css just to setup a page you are looking at 4,000+ lines.
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: [PHP] Multiple pages or Multiple If's?

Post by vitinho444 »

Ahaha i didn't thought about that, plus 600 from alain's DB class and other functions i made and stuff... Well it's about the looks afterall, but since I'm the only coder, screw the looks, the company said: "worry about client perspective", the typical client won't look at my code, and if the page takes 3 seconds to load, they'll blame the internet connection so it's fine :D

Thank you for your help ;)
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Xaos
Posts: 946
Joined: Wed Jan 11, 2012 4:01 am

Re: [PHP] Multiple pages or Multiple If's?

Post by Xaos »

vitinho444 wrote:Well it's about the looks afterall, but since I'm the only coder, screw the looks

Just remember, code like the next guy who is going to look at the code is a psychotic killer with your address ;)
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: [PHP] Multiple pages or Multiple If's?

Post by vitinho444 »

Xaos wrote:
vitinho444 wrote:Well it's about the looks afterall, but since I'm the only coder, screw the looks

Just remember, code like the next guy who is going to look at the code is a psychotic killer with your address ;)
:O I think ill just work at mcdonalds then :P
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Post Reply

Return to “Coding”