Simple question, I like to space my code out a bit. Queries, inserts, functions. And comment them to keep it organized. so 2000 lines becomes 3000 because of this. Does that cause lag? haha also this makes things easier for me too: $sql="SELECT table.field, table.field, table.field, table.field, table.field, table.field, table.field, table.field, table2.field, table2.field, table2.field, table2.field, table2.field, FROM table, table2, WHERE table.field,='$var' AND table2.field, ='$var2' ORDER BY table.field DESC"; $query=mysql_query($sql) or die(mysql_error()); $result=mysql_fetch_array($query); PHP: Insead of having it straight across....is that ok and wont cause lag? (newbie here) <3 thanks = )
No, spacing out your PHP code won't cause any problems at all. If you did the same thing with HTML code, that would increase the size of the file sent to the client, and so would increase the load time of your page, but doing it in PHP won't affect anything. It's a good practice to space out your code, as it makes it easier to read. If you work on projects with other people who have to read your code, they would thank you for spacing it out!
thanks, I didnt know that about html tho. my html is dirty haha . another question came to mind, is there that much of a difference in load time ending php whenever possible and putting html on the page you make, then just printing it or using echo? (i am a print booster) currently i just use print combined with my php code with html. much difference? maybe something to do with caching thankies <3
Technically spacing does matter a little. PHP must parse the entire document, so the longer it is (in bytes) the longer it takes to parse. Blank spaces are mostly negligible though, so I wouldn't be worried about them as long as they are there for a purpose. The fastest way to handle html is to remove it from print and echo statements: <?php some php code { ?> <html here /> <?php } ?> PHP: If you need to echo / print strings, the fastest possible way is to 'echo' strings using commas . Also single ' are faster than ". //fastest echo '<something>' , '<something else>' , trim($some_other_string); PHP: