How to print or return the Album_Id that match User_id or user session ID?

Can Anyone look at the String below and direct me to how would I go about gathering and collecting only the Ablum_Id, Id that matches the user_id in db or user session Id and return the Album Id or first one only and passing it for Hidden fields or url etc…
This is the code I am trying to use to get the information I need.Please help me.


   function check_album_on($album_id){
      
      if(!$album_id) return true; // everybody can add an album if is a registered /author user
      
      $db =& JFactory::getDBO();
      $user =& JFactory::getUser();
      $query = 'SELECT user_id, id, format_id, date FROM #__muscol_albums WHERE id = ' . $album_id ;
      $db->setQuery($query);
      $album_creator = $db->loadResult();
      
      if($album_creator == $user->id) return true;
      else return false;
                          echo ".$album_id" or echo
      
   }

What does loadResult do?

Can you tell me if this will return the album_id that marches the user ID and allow me to echo that ID


			$user =& JFactory::getUser();
			
	$id = JRequest::getVar( 'id' ) ;
	$view = JRequest::getVar( 'view' ) ;
			
	$params = &JComponentHelper::getParams( 'com_community' );
		$itemid = $params->get('itemid');
		   if($itemid != "") $itemid = "&Itemid=" . $itemid;


	//function check_album_on($album_id){
		
		if(!$album_id) return true; // everybody can add an album if is a registered user
		
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();
                          $user_id = $user->id;
		$query = 'SELECT user_id, id, format_id, date FROM #__muscol_albums WHERE id = ' . $album_id ;
		$db->setQuery($query);
		$album_creator = $db->loadResult();
		
		if($album_id == $user_id) return true;
		echo id= '.$album_id';
		
	}

I wrote this below, to get the userid that is in the browser to SQL query against the user_id in album table and get the $album_id or $id.

When my url in the browser is looks like:
http://localhost/index.php?option=com_community&view=profile&userid=xx[B]&id=xx[/B]&Itemid=xx … This works fine.

But I want to work without the “&id=xx”, just like this
http://localhost/index.php?option=com_community&view=profile&userid=xx&temid=xx

SEE CODE


if (!isset($_GET['userid']))
		{
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();
        $userid = $user->id;

		
		$id = $_GET['userid'];
		$query = 'SELECT user_id, id, format_id, year, name FROM #__muscol_albums WHERE user_id = ' . $id;
		//$query = 'SELECT user_id FROM #__muscol_albums WHERE id = ' . $album_id ;
		$result = mysql_query($query) or die('Error, No Album Search failed');
		list($name, $user_id, $id, $year) = mysql_fetch_array($result);
	
	
		//$db =& JFactory::getDBO();
		//$user =& JFactory::getUser();
		//$query = 'SELECT user_id FROM #__muscol_albums WHERE id = ' . $album_id ;
		$db->setQuery($query);
		$album_id = $result();		
	
		echo $id;
		echo $user_id;
		echo $year;
		//exit;
		}	 
	 		
	/* Creating URL */
	$id=JRequest::getVar($prefix . 'id') ;
	$url=JURI::root().'index.php?'.$component.'&id='.$id.'&tmpl=component&print=1';
	for($i=1;$i<count($type);$i++){
		$url.='&amp;'.$type[$i].'='.$layout[$i];
	}
	
	$url.=$custom;
	//$url.=$custom."&id=$id";
	/* End */
	
	/* Getting current User Logged in  Session ID and First Album Id */
	$session=&JFactory::getSession();
	$session_id=$session->getId();
	$id=$session->getId();
	/* End */
	
	/* Starting curl session */
	$c_open=curl_init();
    curl_setopt($c_open, CURLOPT_URL , $url);
    curl_setopt($c_open, CURLOPT_HEADER, 1);
	curl_setopt($c_open, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($c_open, CURLOPT_COOKIE, session_name().'='.$session_id );  
	// Passing session ID.
    
	$result=curl_exec($c_open);
    curl_close($c_open);
    /* End of curl session */