vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Recent Posts Fetching Problem (https://vborg.vbsupport.ru/showthread.php?t=158037)

Infinite Guitar 09-17-2007 12:42 PM

Recent Posts Fetching Problem
 
Hi everyone!

My programmer setup this code to fetch the thread title and username of the latest 8 posts in the forum, but it's acting really weird. It's randomly showing different amounts of recent posts, from none to 3 to 6, when it should always show 8. And it's putting the incorrect thread title over the usernames. It's just acting really weird. Can anyone check out the below code and tell me if you notice anything that needs to be changed?

Thanks so much for any help guys,
Sean

CODE:

<?php
$numberOfPosts = 8;
$rs= mysql_query("SELECT postid, username, title, threadid FROM post ORDER BY dateline DESC LIMIT $numberOfPosts");
while ($row= mysql_fetch_array($rs))
{
if ($row['title']=='')
{
$threadid= $row['threadid'];
$rs2= mysql_query("SELECT title FROM post WHERE postid=$threadid LIMIT 1");
$row2= mysql_fetch_array($rs2);
if ($row2 && $row2['title'])
{
$row['title']= $row2['title'];
}
else
{
continue;
}
}

echo "<tr><td class='red10arial'><a class='whitetogray10' href='/forum/showthread.php?t={$row['threadid']}'>";
echo $row['title'].'</a><br/>'.$row['username'].'';
echo '</td></tr>';
}
?>

Opserty 09-17-2007 01:39 PM

[sql]
SELECT title FROM post WHERE postid=$threadid LIMIT 1[/sql]
FROM post should be FROM thread (I think, or is it "threads" I'm not to sure)

Also you can remove this:
PHP Code:

else
{
continue;


Finally use the PHP BBCode tags when you post PHP code :p


All times are GMT. The time now is 12:20 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01806 seconds
  • Memory Usage 1,709KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete