Reply
Loop not outputting all data
Old 04-04-2008, 10:42 AM Loop not outputting all data
Novice Talker

Posts: 7
Does anyone see a reason why the "show news comments" section of this code is only displaying the newest comment for each post?

$comments_list_commentbit is being called from within the template for "news_newsbit_commentslink". Note that some classes and variables may not appear to be defined as this is only a portion of the script.

PHP Code:
if ($action == '')
{
    
define('ISPRINTABLEPAGE'false);
    
define('WILLTRUNCATE'true);
    
define('ISRSS'false);
    
$templatesused 'news_newsbit, news_newsbit_commentslink, news_avatarbit, news_newsbit_readmorelink, comments_list_commentbit, comments_list_commentbit_removecomment';
    
unp_cacheTemplates($templatesused);
    
$getnews $DB->query("SELECT * FROM `unp_news` ORDER BY `date` DESC LIMIT $newslimit");
    while (
$news $DB->fetch_array($getnews))
    {
        
$catid $news['catid'];
        
$category $categorycache["$catid"];
        
$newsid $news['newsid'];
        
$subject $news['subject'];
        
$newstext $news['news'];
        
$poster $news['poster'];
        
$posterid $news['posterid'];
        
$date $news['date'];
        
$postdate unp_date($dateformat$date);
        
$posttime unp_date($timeformat$date);
        
$avatar unp_checkAvatar($posterid);
        
// begin Show News Comments
        
$getcomments $DB->query("SELECT * FROM `unp_comments` WHERE newsid='$newsid'");
        if (
$DB->num_rows($getcomments) > 0)
        {
            while (
$comments $DB->fetch_array($getcomments))
            {
                
// grab and fix up comments
                
$c_id $comments['id'];
                
$c_title htmlspecialchars(stripslashes($comments['title']));
                
$c_name htmlspecialchars(stripslashes($comments['name']));
                
$c_email htmlspecialchars(stripslashes($comments['email']));
                
$c_date unp_date($dateformat$comments['date']);
                
$c_time unp_date($timeformat$comments['date']);
                
$c_text nl2br(htmlspecialchars(stripslashes($comments['comments'])));
                
$c_ipaddress $comments['ipaddress'];
                
$c_proxy $comments['proxy'];
                
$c_text $n->unp_doSmilies($c_text);
                if (
$isloggedin == 1)
                {
                    eval(
'$removecommentlink = "'.unp_printTemplate('comments_list_commentbit_removecomment').'";');
                }
                else
                {
                    
$removecommentlink '';
                }
                eval(
'$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";');
            }
        }
        else
        {
            
$comments_list_commentbit '';
        }
        
// end Show News Comments
        
if (!$avatar)
        {
            
$useravatar '';
        }
        else
        {
            eval(
'$useravatar = "'.unp_printTemplate('news_avatarbit').'";');
        }
        if (
$commentsallowance == '1')
        {
            
$comments $news['comments'];
            eval(
'$commentsinfo = "'.unp_printTemplate('news_newsbit_commentslink').'";');
        }
        else
        {
            
$commentsinfo ' ';
        }
        
$comments $news['comments'];
        
//$newstext = $n->unp_doNewsTrim($newstext); // Move to unp_doNewsFormat
        
$newstext $n->unp_doNewsFormat($newstext);
        
$subject $n->unp_doSubjectFormat($subject);
        
// NewsBit
        
eval('$news_newsbit = "'.unp_printTemplate('news_newsbit').'";');
        
unp_echoTemplate($news_newsbit);
                
        
// NewsBit
        
echo "\n\n";
    }
    unset(
$news);

spaz is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-04-2008, 01:02 PM Re: Loop not outputting all data
akratellio's Avatar
Average Talker

Posts: 25
Location: Berlin Germany Europe World
Hi spaz,

your results are limited by "LIMIT $newslimit".

mfg

akratellio
__________________
I'm always lying...
Ich lüge immer...
http://www.kcanada.de
akratellio is offline
Reply With Quote
View Public Profile Visit akratellio's homepage!
 
Old 04-04-2008, 02:28 PM Re: Loop not outputting all data
Novice Talker

Posts: 7
$newslimit is set to 50 currently. 6 of 6 test news posts are displayed, its just the comments for each post that aren't displaying all the results when called from outside the loop.
spaz is offline
Reply With Quote
View Public Profile
 
Old 04-05-2008, 04:43 PM Re: Loop not outputting all data
akratellio's Avatar
Average Talker

Posts: 25
Location: Berlin Germany Europe World
Hi Spaz,

are you sure that you get the right newsid out of the news?
The query "SELECT * FROM `unp_comments` WHERE newsid='$newsid'"
is responsable for the output of the comments belonging to the news and
newsid seems to be the glue for both.

mfg

akratellio
__________________
I'm always lying...
Ich lüge immer...
http://www.kcanada.de
akratellio is offline
Reply With Quote
View Public Profile Visit akratellio's homepage!
 
Old 04-07-2008, 05:05 PM Re: Loop not outputting all data
Novice Talker

Posts: 7
Yes, the correct newsid does seem to be getting passed. I've made a little progress. Changing:

PHP Code:
eval('$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";'); 
to:

PHP Code:
eval('$comments_list_commentbit .= "'.unp_printTemplate('comments_list_commentbit').'";'); 
(note the ".") will output all the comments for each news post, but it will also include the comments of the post above it. Why might this be? This notice is also passed at the top of the script output so long as the first post has 1 or more comments:

Code:
Notice: Undefined variable: comments_list_commentbit in /home/x/x/x.com/news/news.php(149) : eval()'d code on line 8
spaz is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Loop not outputting all data
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13630 seconds with 13 queries