Hi,
so for years i have been writing my mysqli queries within the same page as the output of the query. eg
Query at top of the page
Echo results of the query somewhere in the page below
or
Query within the body of the page
Echo results directly below.
I have seen others doing this differently by having an included page of functions that contain the queries and the results outputted on a separate page. What are the advantages of doing this? Should i be doing this?
I am not sure what to google to read about it. Most tutorials just have the query next to the output. If that is perfectly fine then i’ll continue to do that, just wondered if i am missing something important.
So now you want to ask why should we have 3 files instead of one.
That because we think about the future.
For example, two month later we can decide to add RSS feed to our side.
It’s very simple now. Just slightly modify controller:
include('model.php');
$posts = getPosts();
$page = $_GET['page'];
if ($page == 'list'){ include('view.php'); }
if ($page == 'rss'){ include('rss.php'); }