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;
}
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.='&'.$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.'&tmpl=component&print=1';
//} else {
// $url=JURI::root().'index.php?'.$component.'&id=1&tmpl=component&print=1'; //redirect is a function
//}
$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.='&'.$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 */