Printing a function on a content type page? So if I have a custom function with a DB query within template.php such as

function innovista_get_page_children() {

 $result = db_query("SELECT link_path FROM {menu_links}");
 return $result;

}


and I have a content type specific template page, then how do I echo the results in the template file?

I tried this:

&lt;?php
$results = innovista_get_page_children();
foreach($results as $result){
    print $result;
}
?&gt;


I get the following error


  Recoverable fatal error: Object of class stdClass could not be
  converted to string in include() (line 83 of
  /var/www/vhosts/vidanlawnes.co.uk/innovista2/sites/all/themes/innovista/node--level_1.tpl.php).


If I remove print $result; and replace with print 'hello'... e.g

&lt;?php
$results = innovista_get_page_children();
foreach($results as $result){
//print $result;
print 'hello ';
}
?&gt;


It echoes hello out multiple times, so the query is providing results, but I can't seem to print them as $result. Any ideas?

Thanks for your time
The error message itself is clear I think. You are trying to print an object as a string. 
otherwise, your query seems correct. 

function innovista_get_page_children() {

 $result = db_query("SELECT link_path FROM {menu_links}");
 return $result;

}


&lt;?php
$results = innovista_get_page_children();
print '&lt;pre&gt;';
foreach($results as $result){
    print_r($result);
}
print '&lt;/pre&gt;';
?&gt;


Now you will see a formatted variable information of each $result. 
it will look like

stdClass Object (
  [link_path] =&gt; admin/structure/views 
)


So when you print the results, it will be like,

&lt;?php
    $results = innovista_get_page_children();
    foreach($results as $result){
      print $result-&gt;link_path;
      print '&lt;br/&gt;';
    }
?&gt;


However, keep in mind that it's never OK to print link paths or database queries like this. It will cause huge performance problems and will arise security problems. 
Try to use url() and/or l() functions for links (suggested it because you seem to make a link). 
Also, in most cases, there is a function for core/contrib modules to retrive data.