News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

need some help with a custom thread listing mysql

Started by leroymcqy, June 29, 2014, 03:04:34 AM

Previous topic - Next topic

leroymcqy

i am trying to show the recent topics on my page. i am not using ssi functions i am doing through mysql and php.


$result = mysql_query("SELECT * FROM smf_boards AS b JOIN smf_messages AS c  JOIN smf_members AS m ON (b.id_board=c.id_board)  ");

while ($post = mysql_fetch_array($result))
{
$id     = $post['id'];
$title  = $post['subject'];
$topic  = $post['id_topic'];
$board  = $post['id_board'];
$member = $post['id_member'];
$author = $post['member_name'];
$name   = $post['name'];
$body   = $post['body'];
$icon   = $post['icon'];
$slug   = create_slug($title);
$desc   = limit_words($body, '50');
$month  = date('M d, Y', $post['poster_time']);
$reply = $post['num_replies'];

echo '
<h1>'.$title.'</h1>
' . restoreTags($desc) . '';

echo' <div id="comments">Posted by <a href="/forum/profile/' . $author . '.' . $member . '/">' . $author . '</a> |' . $month . ' | <a href="/forum/index.php/topic,' . $topic . '.0.html#disqus_thread">Read More</a></div>

';
}


i did it have it like this:

$result = mysql_query("SELECT * FROM smf_boards AS b JOIN smf_messages AS c  JOIN smf_members AS m ON (b.id_board=c.id_board) JOIN smf_topoics AS t  ");

while ($post = mysql_fetch_array($result))
{
$id     = $post['id'];
$title  = $post['subject'];
$topic  = $post['id_topic'];
$board  = $post['id_board'];
$member = $post['id_member'];
$author = $post['member_name'];
$name   = $post['name'];
$body   = $post['body'];
$icon   = $post['icon'];
$slug   = create_slug($title);
$desc   = limit_words($body, '50');
$month  = date('M d, Y', $post['poster_time']);
$reply = $post['num_replies'];

echo '
<h1>'.$title.'</h1>
' . restoreTags($desc) . '';
if($reply == '0')
{
echo' <div id="comments">Posted by <a href="/forum/profile/' . $author . '.' . $member . '/">' . $author . '</a> |' . $month . ' | <a href="/forum/index.php/topic,' . $topic . '.0.html">no replies</a></div>';
}else{
echo' <div id="comments">Posted by <a href="/forum/profile/' . $author . '.' . $member . '/">' . $author . '</a> |' . $month . ' | <a href="/forum/index.php/topic,' . $topic . '.0.html">',$replies,'</a></div>';
}
}


but this shows double and also shows all with replies when only one would have replies to it.

i just want it to show the posts once without double.

Ninja ZX-10RR

Sorry dude but... What about "www.{your forum name}/forum/index.php?action=recent" ? Isn't it faraway easier?
Quote from: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

margarett

Or via SSI.php, which has a function for it (you say you aren't using it, but why?)... Or a portal, all have a pre-configured block for that.

Anyway, if you really want to go down that route, you should be querying the topics table first, limiting it to the latest "xx" topics. The JOINs are needed to retrieve the complementary information, but the latest topics should be defined through the topics table, not the other way around.
Check SSI.php, function ssi_recentTopics to have an idea how to do it.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

leroymcqy

ssi might be easier but i like the ability to customize my postings. with ssi i can't do that much with that.

so hence why i am using the mysql part.

margarett

You can ;)

If you just call "ssi_recentTopics();", you get the prefabricated layout of SSI. But if you call:
"$topics = ssi_recentTopics(10, null, null, 'array');"
You get the latest 10 topics in an array that you can customize and display as you wish ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

leroymcqy

i figured it out. just without the replies. found out its easier not to include those. i went with disqus comments anyway.

Advertisement: