vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Small problem with LIMIT (https://vborg.vbsupport.ru/showthread.php?t=109268)

KTBleeding 03-02-2006 04:34 AM

Small problem with LIMIT
 
I'm trying to get the last six members to join my forums to show up on the forum home.. I have the basic idea working now, but for some reason the LIMIT isn't working for me.. It's only returning one result.. AKA the last registered member, rather than the last six.

PHP Code:

require_once(DIR '/includes/functions_user.php');

$newest_members_query "SELECT userid, username, joindate
    FROM " 
TABLE_PREFIX "user
    ORDER BY userid DESC
    LIMIT 6"
;

$new_members $vbulletin->db->query_first($newest_members_query);

if(
$new_members[userid]){

    
$new_members[avatarurl] = fetch_avatar_url($new_members[userid]);
    
    if (!
$new_members[avatarurl]) {
    
        
$new_members[avatarurl] = $stylevar['imgdir_misc'] . '/noavatar.gif';
        
    } else {
    
        
$new_members[avatarurl] = $vbulletin->options['bburl'] . '/' $new_members[avatarurl][0];
        
    }
}

eval(
'$newest_members .= "' fetch_template('newest_members') . '";'); 

Any ideas? I'm stumped. :ermm:
Thanks,

Marco van Herwaarden 03-02-2006 07:37 AM

PHP Code:

$new_members $vbulletin->db->query_first($newest_members_query); 

query_first will only retrieve 1 row.
You will need to use query_read, and then a while loop with fetch_array to loop through the results.

KTBleeding 03-02-2006 03:49 PM

1 Attachment(s)
Ah, I see..

Okay, I tried this new approach out but I'm still getting only one result (I have two registered users right now as I'm developing the site..), only user id2 is showing up..

PHP Code:

require_once(DIR '/includes/functions_user.php');

// Gather the six newest members to join
$newest_members $vbulletin->db->query_read("SELECT userid, username, joindate
    FROM " 
TABLE_PREFIX "user
    ORDER BY userid DESC
    LIMIT 6"
);

while (
$new_members $vbulletin->db->fetch_array($newest_members))
{

    
// Get users avatar
    
if($new_members[userid])
    {
        
$new_members[avatarurl] = fetch_avatar_url($new_members[userid]);
        if (!
$new_members[avatarurl]) {
            
$new_members[avatarurl] = $stylevar['imgdir_misc'] . '/noavatar.gif';
        } else {
            
$new_members[avatarurl] = $vbulletin->options['bburl'] . '/' $new_members[avatarurl][0];
        }
    }

eval(
'$newest_members .= "' fetch_template('newest_members') . '";');


There's also a weird, "Resource id #21" that is being displayed now above the user..

Any ideas??

Thanks, Marco

Marco van Herwaarden 03-03-2006 06:37 AM

You are using the same variable name $newest_members for both the SQL-resource and the variable to hold you template output.

KTBleeding 03-03-2006 02:58 PM

That did it.. haha.. man, PHP is a tricky thing..

Thanks a lot Marco! :)

Marco van Herwaarden 03-05-2006 09:24 AM

Nahh PHP is straight forward, the tricky thing is the coder ;)


All times are GMT. The time now is 05:28 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.01594 seconds
  • Memory Usage 1,737KB
  • 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
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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