vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Why would this code not work... (https://vborg.vbsupport.ru/showthread.php?t=65349)

dstruct2k 05-21-2004 04:10 AM

Why would this code not work...
 
PHP Code:

$users explode(" ",$event['users']);
foreach (
$users AS $reggeduser) {
if (
$reggeduser $bbuserinfo['userid']) {
$registered 1;
}



Why wouldn't this work?

$event['users'] is populated with a space-delimited field from the database, full of userids.

dstruct2k 05-21-2004 04:45 AM

Nevermind, must be late... (12:45 AM :))
PHP Code:

        $users explode(" ",$event['users']);
        foreach (
$users AS $index => $value) {
            if (
$value == $bbuserinfo['userid']) {
                
$registered 1;
            }
        } 


dstruct2k 05-26-2004 05:05 PM

Similar idea now, but now I want to join "$users" with the `user` table to get the username of every registered user. :) Ideas?

I could do it where 1 query is executed for every userid registered, but that's very.... excessive. :)

dstruct2k 05-26-2004 05:11 PM

How's this?

PHP Code:

        $userids explode(" ",$event['users']);
        foreach (
$userids AS $index => $value) {
            if (
$firstdone 0) {
                
$querystuff "$value";
                
$firstdone 1;
            } else {
                
$querystuff .= "OR WHERE userid = $value";
            }
        }
 
        
$names DB_site->query_first("SELECT * FROM " TABLE_PREFIX "user WHERE userid = $querystuff"); 

It's just kinda random thoughts put into code, but would it do what I want?

Xenon 05-27-2004 12:31 PM

that's bad, and not working at all ;)

better way:

PHP Code:

$userids explode(' '$event['users']);

// make sure to have at least one id
$userids[] = 0;

//now get users and their names:
$users $DB_site->query("
    SELECT userid, username
    FROM " 
TABLE_PREFIX "user
    WHERE userid IN (" 
implode(', '$userids) . ")
"
);

//and now loop through the event users.
while($user $DB_site->fetch_array($users))
{
    
// do your stuff in here.




All times are GMT. The time now is 04:11 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.01209 seconds
  • Memory Usage 1,733KB
  • 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
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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