1 (edited by Krilik 2004-07-06 09:24)

Topic: Displaying recent topics from a user

I've been trying to figure out to display the most recent threads by a user. The only problem is I don't know how to code the result to only fetch topics posted by a certain user. The code would look like this:

$result = $db->query('SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE poster='.$username.' ORDER BY last_post DESC) or error('Unable to fetch topics from user, __FILE__, __LINE__, $db->error());

The part in red is what I don't get. I set the variable $username to the username of the user of the profile you're in. The code I used for that is:

$username = $user['username'];

But when I try to display the results from the database I get an error. I'm a newb at MySQL so I was just wondering if it would be possible.

I'm trying to write this mod into the profile.php in a table underneath the users profile around line 923.

Re: Displaying recent topics from a user

Try this:

$result = $db->query('SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE poster=\''.$username.'\' ORDER BY last_post DESC') or error('Unable to fetch topics from user', __FILE__, __LINE__, $db->error());
"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Displaying recent topics from a user

Works perfect thanks wink