Display database query results in custom module
To be able to exploit your result, you should fetch your result with one of the function of the Statement class.

If you use the function fetchAll() for example, you will have an array of objects with all your result.

$results = $query-&gt;execute()-&gt;fetchAll();


You can do a function to create your markup with that array. 

You can also not use a function from Statement and do a foreach directly on the result generate by the execute() function to create your markup

$results = $query-&gt;execute();

foreach($results as $res) {
    $markup .= "&lt;tr&gt;&lt;td&gt;$res-&gt;field_1&lt;/td&gt;&lt;td&gt;$res-&gt;field_2&lt;/td&gt;&lt;/tr&gt;";
}


If you want see how is design your array, you can install the module kint (from the devel module) and display your result with 

ksm($results);


Additionnally, to work, your query should have the list of fields it should select.

$query-&gt;fields('m', ['field_1', 'field_2']);