Using url userid to table user_id to return the table ID or album_id

There is something wrong with my statement it is not returning sql queries results based on matching the url based based userid to match with the table user_id and get the Ablum id and Album name:

Results are die(‘Error, No Album Search failed’); How do I get the Id

Please hlep:


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

		
		$album_id = $_GET['userid'];
		$query = 'SELECT user_id, id, format_id, year, name FROM #__muscol_albums WHERE user_id = ' . $album_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);
		
	
		echo $id;
		
		//exit;
		}

First of all you have no idea if your SQL statement is correct so replace that error message string with mysql_error().

Then come back here and post the result.

I ran the quey, it appears to run correctly, but I want the browser url to not need to have ID=xx in it?

where the userid=xx matches the Id=xx ran in script

like this http://site/index.php?option=com_community&view=profile=userid=45

Can you help me get query to insert the correct ID in the $url field and not need in the borser url location to be read???

To hide the userid from the URL you’ll need to pass userid either in POST method (which you can only do if it originates from a form) or else within a Session variable.

Either way theres some code changes to be done outside of the segment you posted, and checks that those changes wont effect other pages and functions.

The userid is passed from previous apges and is listed in borwser url and can be read a var or get.
I would leikt o query the userid = user_id from the muscol_album table and get back the ID of that match. What am I missing to get it to run the query and return the correct value, I have and If else statement that goes to another url and places default ‘id=1’

I want the$url= with the correct id of that user??? HELP PLEASE


/* Creating URL */
	$id=JRequest::getVar($prefix . 'id') ; 	
	if($id!=''){
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();
        $user_id = $user->id;

		
		$id = $_GET['userid'];
		$query = 'SELECT user_id, id, format_id, year, name FROM #__muscol_albums WHERE user_id = ' . $user_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);  
	     $url=JURI::root().'index.php?'.$component.'&id='.$id.'&tmpl=component&print=1';
	} else {
     $url=JURI::root().'index.php?'.$component.'&id=1&tmpl=component&print=1'; 
	 //redirect is a function 
	}	
	//$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 */

please take a look at code below… IAm trying to parse the userid from borwser to matcht eh user_id in table in DB then reutn it vaues, especially value for ID

HELPPPP


// no direct access
defined('_JEXEC') or die ('Restricted access');

/* Getting Parameters */
$component= $params->get('component','');
$view= $params->get('views','');
$custom=$params->get('custom','');
$auto=$params->get('autojscss','0');
$js=$params->get('customjs','');
$css=$params->get('customcss','');
$head_js=$params->get('custombodyjs','');
$head_css=$params->get('custombodycss','');
$id      = JRequest::getVar($prefix . 'id') ;
/* End of Parameters */



$type=array();
$layout=array();
if($component!=''){
	/* Getting components parameters like task, view, layout, etc. */
	$re1='.*?';	
	$re2='(?:[a-z][a-z0-9_]*)';	
	$re3='.*?';	
	$re4='((?:[a-z][a-z0-9_]*))';	
	$re5='.*?';	
	$re6='((?:[a-z][a-z0-9_]*))';	
	if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6."/is", $view, $matches)){
		$type=$matches[1];
		$layout=$matches[2];
	}
	/* end */
	
    /* Passing Album Id from URL in borwser
		
      if(isset($_GET['id']) && is_numeric($_GET['id']))
              {
               if(intval($_GET['id'])=== null){
                echo '$id is a null and belongs to Administrator';
              }
         else
          {
        echo "NO ALBUM ID FOUND. SORRY.";
       }
			  
	}
	 */
	 
		if (!isset($_GET['userid']))
		{
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();
        $userid = $user->id;

		
		$id = (!isset($_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);
	
	 
		
	
		echo $id;
		echo $user_id;
		echo $year;
		//exit;
		}	 
	 		
	/* Creating URL */
	
	//if (!empty($_GET['id']) && (intval($_GET['id']) == $_GET['id'])) { 
	//     $url=JURI::root().'index.php?'.$component.'&id='.$id.'&amp;tmpl=component&amp;print=1';
	//} else {
    // $url=JURI::root().'index.php?'.$component.'&id=1&amp;tmpl=component&amp;print=1'; //redirect      is a function 
	 
	//}
	$id=JRequest::getVar($prefix . 'id') ; 		
	$url=JURI::root().'index.php?'.$component.'&amp;id='.$id.'&amp;tmpl=component&amp;print=1';
	for($i=1;$i<count($type);$i++){
		$url.='&amp;'.$type[$i].'='.$layout[$i];
	}
	
	//$url.=$custom;
	$url.=$custom."&amp;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 */