How can I make a link to a node obtained from an SQL query? I'm trying to make a module for a users profile page which shows all of the content of certain types they have created. I have got the query to work and list the results in a block - however I can not get the returned list to contain links to the nodes. Here is my code:

function get_articles()
{
  if(arg(0) == 'user' &amp;&amp; is_numeric(arg(1)))
  {
    $account = user_load(arg(1));
  }

  $result = db_query('SELECT node.title FROM {node} node WHERE (( (node.uid = :uid) AND (node.status = \'1\') AND (node.type IN (\'article\')) )) ORDER BY `created` DESC LIMIT 5', array(':uid' =&gt; $account-&gt;uid));

  if($result-&gt;rowCount() &gt; 0)
  {
    $list = array(
      '#theme' =&gt; 'links',
      '#links' =&gt; array(),
    );

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

    return drupal_render($list);
  }
  else
  {
    return t('This user has no Articles.');
  }
}


Thank you in advance to anybody who answers.
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;