Jump to content

[SOLVED] I am strugling to perform this little task


npsari

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.