PDA

View Full Version : Query ends after 1 loop


Twilkey
03-11-2011, 10:28 AM
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.

$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'], 0, 30) . '...';
$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();
} <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 $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.