SQLTeam.com | Weblogs | Forums

Help outputing record for logged in user ASAP!


#1

Hey I need some help with this bit of code it for PHP

So you visit the site and are logged in the code for your startpage is supposed to show you only your own latest activity, favorite, likes etc.. But for some reason I cannot get it to single out the logged in user, only everybody else. I did not write this code, but it is the only thing I have to work with.

// I added this bit to get the user info
// Get USER info
$user = JFactory::getUser();
$email = $user->email;

// This section joins to tables to display the complete record
// build the SQL query
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select ('com.article_id, com.email, com.publish_date, com.published, con.id, con.title, con.images');

// From the comments table
$query->from('#__joocomments as com');

// From the contents table
$query->from('#__content as con');

// Declaration to select to comment
$query->where('com.article_id=con.id');
$query->where('com.published=1');

// Select only the comments from the logged in user,
// But It never works no matter how I format it.
// I have been trying for months! Please tell me what I am doing wrong..
$query->where('com.email=$email');

//Ordering the comments
$query->order('publish_date desc limit 20');

// Reset the query using our new query object

	$db->setQuery($query); 

// Load the results as a list of stdClass objects.

	$rows = $db->loadObjectList(); 	

// Retrieve each value in the ObjectList

?>


#2

dunno much about php, but are you not replacing the WHERE condition with the three

$query->where

statements?

Also this is a T-SQL (Microsoft SQL Server) forum. It looks like you may be using MySql


#3

Is there a difference? Sorry Not familiar with that. though this was the right place to post the question. this sql stuff is all trial and error for me.


#4

lots of differences, large and small!


#5

e.g. SQL Server does not have a 'LIMIT' clause (uses TOP or OFFSET/FETCH instead)