Do you know the code to pull just a random post from one specific topic.
Nothing fancy, want to use it for dispaying thoughts of great people witch are posted by the members. It would be some 300 or so characters long...
If it's not a lot of extra coding, would it be possible to display the author's name underneath it?
This is the basic code for what you want:
global $db_prefix, $scripturl;
$topic_number = 2; // fill in the number of the topic you want to pull your info from
$query = db_query(
"SELECT *
FROM {$db_prefix}messages
WHERE `ID_TOPIC` = $topic_number
ORDER BY RAND( )
LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// set up your printout
// variables:
// $row['ID_MEMBER']
// $row['posterName']
// $row['body']
I'm assuming that by "author's name" you mean the member's name that posted it. The original author's name would have to be within the post.
At this point, the code doesn't print anything out. It just sets up the variables so that you can format the results however you want. Also, be aware that it will display a different quote each time the page is refreshed.
Thanks...could you explain what you mean with setting up the variables. I really have no clue with any scripting, just can find my way most of the time.
What do i need to set up in your code to just pull random posts/reply from topic 2 for example.
I'll need you to give me an example of how you want your quote to be displayed. Invariably, when I guess at the format someone wants, I get it wrong and have to redo it.
OK..I made this little foto to show it. The box should have a fixed sixe of some 6 lines with possibility for scrolling if bigger.
You see the text (the murphy is just the part of the post itself) and underneath it the username witch is clickable(or not if it's to much work). On the right side of the username you see the "more" text witch would lead you to the end of the topic this post is being pulled from.
The text size should be just small as normally it is in the boxes (i also forgot to modufy it in the pic)
The whole thing (text, username, and more) should be centered (i forgot to modify it in the pic too )
Hope it's not to much coding...
I don't know how to do the "The box should have a fixed sixe of some 6 lines with possibility for scrolling if bigger" thing. I know it's a css function, but somehow I can never get it to work. Maybe someone else can tell you how to do that. I'm also not sure how to get to the bottom of a topic. I can get to the first post of a topic or a specific post in the middle of the topic, but I don't know about the end without a whole lot more coding. The code below will get you to the first post.
Use the code I posted above and then add this below it:
echo '<div style="text-align: center;" >' . $row['body'] . '<br />';
echo '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a> ';
echo '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '">More</a></div>';
If you want different colors, you can either set them in the .css file or inline within the a href statement, like
echo '<a style="color:red;" href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '">More</a></div>';
Wow thanks..this should definately go in the index of tips and tricks. It looks good. For the box size i added this in the div tag and works perfectly.
width: 150px; height: 200px; overflow: auto;
Ok to put all together for the ones that want the fixed box size with a scroll possibility if the text ecseeds the hight, and the colored link to the topic:
global $db_prefix, $scripturl;
$topic_number = 2; // fill in the number of the topic you want to pull your info from
$query = db_query(
"SELECT *
FROM {$db_prefix}messages
WHERE `ID_TOPIC` = $topic_number
ORDER BY RAND( )
LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// set up your printout
// variables:
// $row['ID_MEMBER']
// $row['posterName']
// $row['body']
echo '<div style="text-align: center; width: 150px; height: 200px; overflow: auto;" >' . $row['body'] . '<br />';
echo '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a> ';
echo '<a style="color:red;" href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '">More</a></div>';
Thanks again man... ;)
Oh...didn't know :D. There are not much women around coding so...
Thanks again, woman :P
;D You're welcome. Glad I could help.
Also glad you got the scroll thing to work. I used exactly the same code as you did and it didn't work for me. I think css just doesn't like me sometimes.
Anyway, I'm happy you have it the way you want it.
i like this code! thanks! a bit of a request if this is possible to do.
is it possible to display the avatar and username (which is linked to its profile) of the author of the specific topic or thread everytime the random post is displayed?
and how do i edit the code so that the "MORE" text is underneath the poster name instead of besides it. all of them aligned to the center.
this is what it would look like in a sidebar
Avatar of author or thread starter
Username (linked to profile)
Random post in that topic
Poster name (same format, linked to profile)
More (same, linked to the specific post)
obviously, i don't have any knowledge of php :uglystupid2: so please help :)
thanks in advance!
please help anyone?
what are the things i need to edit if i want to put this code in a center block?
thanks in advance
hi jpdeni,
need your help in this one :) i really liked this code as this always provide a "new" post in my frontpage.
how do i display an image before the generated random post?
thanks in advance
Assuming this is the code for printing out the post:
echo '<div style="text-align: center; width: 150px; height: 200px; overflow: auto;" >' . $row['body'] . '<br />';
use
echo '<div style="text-align: center; width: 150px; height: 200px; overflow: auto;" ><img src="http://www.url/to/image.jpg">' . $row['body'] . '<br />';
Sorry I didn't respond to your earlier posts. I was in the hospital at the time you posted them.
thanks heaps, jpdeni!
QuoteSorry I didn't respond to your earlier posts. I was in the hospital at the time you posted them.
it's all good, jpdeni.. you've done enough.. thanks again.. don't bother with it..