Good day.
do not judge strictly, fully yet do not understand what, where and why at 100% ...
there is a rather poor script. For example, we have three parts (different files are responsible for everything, generally dregs ...) title breadcrumb content
When you go to the news page, THREE requests are made to pull out this news! As they probably guessed, the title (browser's title page), bread crumbs (breadcrumb), and the news itself (content) were guessed. Naturally, this does not suit me. And I decided that it was easier to jot down a small class and when moving to the news, shove everything as an array into a class property, and according to the script, drag everything out of it.
Those. a class property has, let's say, a conditional "buffer". When entering the page, all the data in the property, and in breadcrumbs and the header, I already pull from it (the properties), avoiding requests.
Is this approach normal? Because nothing else comes to mind is as simple.
UPD
Although I do not care for the cons. But I do not like when they do not write the reason. It was thought that because of my stupid question. But he also suggested that, due to the lack of an example, I was asking about something. Here is an example.
class News { public $newsArray = array(); public function __construct() { if (isset($_GET['id']) && !empty($_GET['id'])) { $this->get($_GET['id']); } } public function get($id) { $query = mysql_query("SELECT * news WHERE id = '".(int)$id."'"); if (mysql_num_rows($query) > 0) { $r = mysql_fetch_array($query); $this->newsArray = $r; return $r; } else return false; } }
UPD 2 So no one has any idea why it’s so bad and how to avoid three queries and make one if the data is needed in three different files? Explain noob please. After all, not everyone immediately began to write a mega-code.