Fenhopi Posted June 21, 2011 Share Posted June 21, 2011 So, I don't want my index page to be to crowded with code. Such as queries and db connections taking over half my page makes it all look untidy. Is it a way that I can store my queries, etc on a page, and just call on it? Or a similar solution? Thank you in advance Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/ Share on other sites More sharing options...
TeNDoLLA Posted June 21, 2011 Share Posted June 21, 2011 Save the content to a different file for example for functions or classes or database actions and then use include at a file where you want to use them. require_once('someFunctions.php'); Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/#findComment-1232909 Share on other sites More sharing options...
Fenhopi Posted June 21, 2011 Author Share Posted June 21, 2011 OKay, do I just put that on the top of the page, or where I normally would have put the queries? Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/#findComment-1232965 Share on other sites More sharing options...
TeNDoLLA Posted June 21, 2011 Share Posted June 21, 2011 I guess you can do both. I usually include needed files at the top unless theres some reason not to do so. Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/#findComment-1232968 Share on other sites More sharing options...
Fenhopi Posted June 21, 2011 Author Share Posted June 21, 2011 Okay, what if the queries are in a while loop? Do I just require it within the loop? Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/#findComment-1233035 Share on other sites More sharing options...
Zane Posted June 21, 2011 Share Posted June 21, 2011 Never include/require a page within a loop. It's not just bad practice, it's downright illogical. Include at the top like you said before. Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/#findComment-1233036 Share on other sites More sharing options...
Fenhopi Posted June 21, 2011 Author Share Posted June 21, 2011 Alright.. that makes things harder, seeing as some of the queries depends on the information gathered from the loop.. Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/#findComment-1233037 Share on other sites More sharing options...
Zane Posted June 21, 2011 Share Posted June 21, 2011 post code (in CODE tags) for quality assistance. Link to comment https://forums.phpfreaks.com/topic/240016-calling-a-piece-of-code-from-a-different-page/#findComment-1233038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.