Jump to content

[SOLVED] I am strugling to perform this little task


Recommended Posts

Allow me to introduce you to my database...

 

I have a table called phpbb_topics

and a table called phpbb_users

 

I want to display the latest 10 topics (and the image of who posted them)

 

I did this but doesnt work!

 

$q = "SELECT * FROM phpbb_topics, phpbb_users ORDER BY topic_last_post_id DESC LIMIT 10;";
$res = @mysql_query($q);
while($r = @mysql_fetch_array($res)){

print "<IMG src=\"/forums/images/avatars/$r[user_avatar]\">";
echo "<a href='/forums/viewtopic.php?t={$r['topic_id']}'>{$r['topic_title']}</a><br>";
print "Views: $r[topic_views]";
print "  ";
print "Replies: $r[topic_replies]";
}

 

phpbb_users has a row called user_id

and phpbb_topics has a row called topic_poster (These are the 2 equal ones)

 

Can you show me how to write the $q please

thanks for the code

 

i tried it, everything works ok, however, the image is not showing

 

The image row is called user_avatar and it is available in the table phpbb_users

 

do you know what should i add to the code you sent me

Oops, sorry...I left that field out.

 

SELECT t.topic_id, t.topic_title, t.topic_views, t.topic_replies, u.user_avatar
FROM phpbb_topics t
LEFT JOIN phpbb_users u
ON u.user_id = t.topic_poster
ORDER BY t.topic_last_post_id DESC LIMIT 10

I don't know what your field names are called that link the tables, but something like this.

 

SELECT t.topic_id, t.topic_title, t.topic_views, t.topic_replies, u.user_avatar, p.post_time
FROM phpbb_topics t
LEFT JOIN phpbb_users u
ON u.user_id = t.topic_poster
LEFT JOIN phpbb_posts p
ON p.poster_id = t.topic_poster
ORDER BY t.topic_last_post_id DESC LIMIT 10

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.