Possible Duplicate:
related article function code in PHP for Joomla

I am creating a Joomla Ingredient that returns data in encoded json format to have an Android Application. Anyway, I have to return the attached articles of the specific article whose ID is succumbed the url as Publish. What is the suitabe PHP code for that model function that returns the attached articles?

This is what I emerged with to date:

function getRelatedArticles($id){ 
$db =& JFactory::getDBO();

    // select the meta keywords from the item
    $query = "SELECT `metakey` FROM `#__content` WHERE `id`=".$id;

    $database->setQuery( $query );

    if ($metakey = trim( $database->loadResult() )) {
    // explode the meta keys on a comma
    $keys = explode( ',', $metakey );
    $likes = array();

    // assemble any non-blank word(s)
    foreach ($keys as $key) {
    $key = trim( $key );
    if ($key) { 
        $likes[] = $key; 
  if (count( $likes )) {
   // select other items based on the metakey field 'like' the keys found
   $query = "SELECT id, title"
    . "nFROM #__content"
    . "nWHERE id<>$id AND state=1 AND access <=$my->gid AND (metakey LIKE '%";
   $query .= implode( "%' OR metakey LIKE '%", $likes );
   $query .= "%')";
   $database->setQuery( $query ); */
   $related = $database->loadObjectList()

  return $related;