How can I make a link to a node obtained from an SQL query?
foreach($result as $record)
{
  $list['#links'][] = array('title' =&gt; $record-&gt;title, 'href' =&gt; $account-&gt;name . '/' . $node-&gt;title);
}


You have $node->title in this code, but there is no $node object.  The href appears to be the user's name, and then the title of a node?  So the link would be http://example.com/johndoe/My Page Title, which doesn't seem right.

Is this what you're trying to do?  First, add node.nid to your list of SQL columns

foreach($result as $record)
{
  $list['#links'][] = array('title' =&gt; $record-&gt;title, 'href' =&gt; 'node/' . $record-&gt;nid);
}


You might also look into bypassing the $list array, and the drupal_render() function, and simply use:

$links = "&lt;ul&gt;";

foreach($result as $record)
{
  $links .= "&lt;li&gt;" . l($record-&gt;title,'node/'.$record-&gt;nid) . "&lt;/li&gt;";
}

$links .= "&lt;/ul&gt;";

return $links;