Moving To Object Orientated Programming
TL;DR: Read about MVC and understand the basics and then learn laravel

This is not about object oriented approach but more like a separation of concerns thing. You have two concerns for the moment:


You're collecting some data
You're displaying it


so what you have to do is to separate them, start by using a template system like twig or smarty. Collect the data in some php and pass it to the template file and render it so the html code and php code will be separated. 

The template will be responsible of "how" you display the data and your php file will be responsible of "preparing the data" for the template.



Second step is to separate the code that is "dealing with the data" from the code that is "setting up the template". You can move the data related code to some class so that you'll have smt. like this in the end:

&lt;?php 

// Require classes, setup things etc.

$obj = new Events;
$events = $obj-&gt;getAllEvents();

echo $tpl-&gt;render('events/index.tpl', array('events' =&gt; $events));




Third step may be about the // Require classes, setup things etc. part in the example above. You can use a front-controller to deal with that...

... and the list goes on...

After some struggling you'll start to realize that you need some helper classes to deal with the http requests, responses, sessions etc.

...and you'll need more and more "concerns" to "separate" in the future and in the end you'll understand why people are using mature frameworks these days.

I was writing like this in 1997-1998 (no kidding) because I had to, but you don't :)