Page 1 of 1

[PHP] Multiple pages or Multiple If's?

Posted: Mon Jun 09, 2014 1:13 pm
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?

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

Posted: Mon Jun 09, 2014 1:37 pm
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.

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

Posted: Mon Jun 09, 2014 3:13 pm
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 ;)

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

Posted: Mon Jun 09, 2014 5:56 pm
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!' />";
}


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

Posted: Mon Jun 09, 2014 6:12 pm
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 ;)

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

Posted: Tue Jun 10, 2014 2:55 am
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 ;)

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

Posted: Tue Jun 10, 2014 6:51 pm
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.

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

Posted: Wed Jun 11, 2014 2:09 pm
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 ;)

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

Posted: Wed Jun 11, 2014 2:12 pm
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 ;)

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

Posted: Wed Jun 11, 2014 2:59 pm
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