vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Query ends after 1 loop (https://vborg.vbsupport.ru/showthread.php?t=260209)

Twilkey 03-11-2011 10:28 AM

Query ends after 1 loop
 
What about this code could cause only one row to be displayed?

I have tried this with $blogs = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "blog");
and there are over 1000 entries to display, so I am pretty sure the query is fine. I tried deleting the avatar code just to see if it helped, but when I go to save the plugin, I get a 301 error. So i can not even get rid of that code to test.

PHP Code:

$blogs $db->query_read("SELECT * FROM " TABLE_PREFIX "blog WHERE `state` = 3 ORDER BY dateline DESC LIMIT 0, 3");  
   
  while (
$blog $db->fetch_array($blogs))  
  { 
    
$blog[blogid] = $blog['blogid'];  
    
$blog[title] = substr($blog['title'], 030) . '...'
    
$blog[comments] = $blog['comments_visible'];  
    
$blog[userid] = $blog['userid'];  
    
$blog[username] = $blog['username']; 
    
$blogdate vbdate($vbulletin->options['dateformat'], $blog['dateline'], true); 

               
//Avatar Display 
               
$avatarurl1 fetch_avatar_url($blog[userid]); 
                       if (
$vbulletin->options['usefileavatar']) 
                       {                            
                           if (
$avatarurl1
                           { 
                                 
$avatarurl $vbulletin->options['bburl'] . '/' $vbulletin->options['avatarurl'] . '/avatar' $blog[userid] . '_' $blog[userid] . '.gif'
                           } 
                           else 
                           { 
                                 
$avatarurl $vbulletin->options['bburl'] . "/review/images/noavatar.gif"
                           }     
                       } 
                       else 
                       { 
                           if (
$avatarurl1
                           { 
                                 
$avatarurl $vbulletin->options['bburl'] . '/image.php?u=' $blog[userid]; 
                           } 
                           else 
                           { 
                                 
$avatarurl $vbulletin->options['bburl'] . "/review/images/noavatar.gif"
                           }                             
                       } 
        
$blog_bits vB_Template::create('news_blog_bit'); 
        
$blog_bits->register('blogid'$blog[blogid]); 
        
$blog_bits->register('blogtitle'$blog[title]); 
        
$blog_bits->register('blogcomments'$blog[comments]); 
        
$blog_bits->register('bloguserid'$blog[userid]); 
        
$blog_bits->register('blogusername'$blog[username]); 
        
$blog_bits->register('blogdate'$blogdate); 
        
$blog_bits->register('avatarurl'$avatarurl); 
        
$blog_bits .= $blog_bits->render();    
  } 

HTML Code:

<li class="forumbit_nopost L2" id="catblogs">
    <div class="forumrow L2">
                    <a href="blog.php?b={vb:raw blogid}" target="_blank"><img src="review_sidebarimage.php?image={vb:raw avatarurl}" class="forumicon" border="0" /></a>
        <div class="forumdata">
<div class="datacontainer">
            <h2 class="forumtitle"><a href="blog.php?b={vb:raw blogid}" class="forumtitle">{vb:raw blogtitle}</a></h2>
            <p class="tcatDesc">
            Posted By: {vb:raw blogusername}<br />
            Posted On: {vb:raw blogdate}<br />
            Comments: {vb:raw blogcomments}</p>
        </div>
</div>
    </div>

</li>


Boofo 03-11-2011 11:32 AM

LIMIT 0, 3 is only going to give you the first 3 results from the database. And the end } should be after the while loop (before //Avatar Display), shouldn't it?

Twilkey 03-11-2011 12:01 PM

3 results is what I wanted, and as for the last }. Doing that would just cause the whole thing to stop working.

Either way, I figured out the problem. I used $blog_bits to create the template and register the variables, then I also used the same to store the render of the template. You can not do that. So I simply made
PHP Code:

$blog_bits .= $blog_bits->render();
into 
$blog_bit 
.= $blog_bits->render(); 

It was a simple mistake on my part.

Thanks for your input though Boofo.

Boofo 03-11-2011 12:21 PM

Glad you got it. I still don't see why you need the Avatar Display and the template render in the while loop. But that doesn't matter now that you have it working.


All times are GMT. The time now is 12:18 AM.

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.01295 seconds
  • Memory Usage 1,756KB
  • 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_html_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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