Help, get userid with else _GET

Ok, hot to incorporate that with a running and else statement:
Where if $user->id is not the user in url, then use the $userid from GET. in url.


// Return with empty data
		if ($user->id == null || empty($user->id)) {
		//return false;
		}
		// Query the database for the user
		$sql = 'SELECT * FROM jos_muscol_albums WHERE user_id = ' . $user->id;
} else if isset($_GET['userid']) ? (int)$_GET['userid'] : JRequest::getVar('userid');  
		// Query the database for the user
		$sql = 'SELECT * FROM jos_muscol_albums WHERE user_id = ' . $_GET['userid'];
}		
		$result = mysql_query($sql) or die('Error, No Album Search failed');
		//$result = mysql_query($sql) or die('Error, No Album Search failed<br />' . mysql_error());   
		
		if (mysql_num_rows($result) > 0) {
		list($id, $year, $name) = mysql_fetch_array($result);
		
		// Display the results
		//echo $id . '<br />' . $user->id . '<br />' . $year;
		//echo $name;

Something like this should do it:


if ((isset($_GET['userid'])) and ($userid != $_GET['userid']))
   {
   $userid = $_GET['userid'];
   }

Or


<?php
if (count($_GET['field']) > 0) {

}

I tried both methods and it still takes the information of only th user that is login.

I want it to pass the information of user in the browser, but I am not smart enough to figure this out.

help if you can…


// Set cookie
		$userid = JRequest::getVar('userid');
        //$userid = JRequest::getVar('userid', 'User id goes here', 'GET');
		
		$data = new stdClass();
		//$model =& $this->getModel('Profile');
		//$album		= & $this->get( 'Data');
		$my = CFactory::getUser();
		
		// Test if userid is 0, check if the user is viewing its own profile.
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();
		
		// Return with empty data
		if ($user->id == null || empty($user->id)) {
		//return false;
		}
		// Query the database for the user
		$sql = 'SELECT * FROM jos_muscol_albums WHERE user_id = ' . $user->id;
		//$query = 'SELECT user_id FROM #__muscol_albums WHERE id = ' . $album_id ;
		
		
		$result = mysql_query($sql) or die('Error, No Album Search failed');
		//$result = mysql_query($sql) or die('Error, No Album Search failed<br />' . mysql_error());   
		
		if (mysql_num_rows($result) > 0) {
		list($id, $year, $name) = mysql_fetch_array($result);
		
		// Display the results
		//echo $id . '<br />' . $user->id . '<br />' . $year;
		//echo $name;
		
		
		
			 
	// Preform id return check and redirecto to correct url
	    //$id=JRequest::getVar($prefix . 'id') ;
		//$id = JRequest::getVar('userid');
		//if ($user->get('id') == 0 || $userid == 0 || $userid <> $user->get('id')){ 
		
		if ($user->get('id') == 0 || $userid == 0 || $userid <> $user->get('id')){
		
     	//$url = JURI::root() . 'index.php?' . $component . '&id=' . $id . '&amp;tmpl=component&amp;print=1';
       $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];
	  }
	
		}else {
     $url = JURI::root() .'index.php?option=com_muscol&amp;view=album&amp;id=23&amp;tmpl=component&amp;print=1'; 
		  }
		
		  } else {
		echo 'User Album Loading...';
		} 			
	/* 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 */
	
	/* 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 */

I prefer to use this technique, which ensures that the variable is correctly set even if the condition fails:


$userid = '';
if (isset($_GET['userid'])) {
    $userid = $GET['userid'];
}

Or, if you have PHP 5.2 or better:


$userid = filter_input(INPUT_GET, 'userid');

Paul,

Nuff thank bro.

I changed this lines of code from:


		 if ($user->id == null || empty($user->id)) {
		//return false;
		// Query the database for the user
		$sql = 'SELECT * FROM jos_muscol_albums WHERE user_id = ' . $user->id;
		//} 

to


		if (isset($_GET['userid'])) {    
		$userid = $GET['userid'];}

		// Query the database for the user
		$sql = 'SELECT * FROM jos_muscol_albums WHERE user_id = ' .$_GET['userid'];

It works…

This part does not work, if the user does not return and ID or id == null it should go to a default url it is inot what am I missing:


	if ($id) {
		if ($user->get('id') == 0 || $userid == 0 || $userid <> $user->get('id')){	
     	//$url = JURI::root() . 'index.php?' . $component . '&id=' . $id . '&amp;tmpl=component&amp;print=1';
       $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];
	  }
		}
		} else if($id == null) {
     $url = JURI::root() .'index.php?option=com_muscol&amp;view=album&amp;id=25&amp;tmpl=component&amp;print=1'; 
		  }
		
		  } else {
		echo 'User Album Loading...';
		}