Create a form programmatically and display result on template
I recommend adding the results of the query to the form markup-like:

$form['something'] = array(
  '#theme' =&gt; 'statistiques_template',
  '#vartest' =&gt; $vartest,
);


is equivalent to theme('statistiques_template', array('vartest' =&gt; $vartest)) -- the theme system will remove the # from the variable names if #theme is set.

But, of course, you can add the form to the page build as well, see how comment_reply does it:

  $build['comment_node'] = node_view($node);
  $build['comment_form'] = drupal_get_form("comment_node_{$node-&gt;type}_form", (object) $edit);


If coding in Drupal 7, forget direct theme calls, strings and the . operator. Work with render arrays instead. It's also a good preparation for Drupal 8 where concatenating strings leads to double escape bugs.