vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Userid into an interval (https://vborg.vbsupport.ru/showthread.php?t=249486)

milla da killa 08-28-2010 03:00 PM

Userid into an interval
 
Working on a code for a clan website which would assign each member a service number, even though this should be simple, I simply cannot get it to work. The plan was originally to take the user's id number, and simply add that to 0000 (thus getting a 4 digit number, such as 0123). Issue is, that I can't seem to get it convert to an integer so I can add it (and all attempts wind up echoing "4 + 0000" or something of the like). So, want to know how I could convert the user id to an integer so I can pull this off, or a code to get this to work.

Any help would be greatly appreciated.

/n00b question

BirdOPrey5 08-28-2010 03:26 PM

There's probably a better way but you could...

Use if statements to check if the UserID is < 10, <100, <1000
and if it is less then 10 day make a new string say $userstring = "000" . $userid
if it's less than 100 $userstring = "00" . $userid
if less than 1000 $userstring = "0" . $userid
else $usserstring = $userid

milla da killa 08-28-2010 03:52 PM

PHP Code:

function servicenumber($userstring)
{
if (
$userid 10) {
$userstring "000" $userid;
}
if (
$userid 100) {
$userstring "00" $userid;
}
if (
$userid 1000) {
$userstring "0" $userid;


Would this be right? If it is, I would be good just putting this in the functions.php file right?

Brain dead at the moment apparently, doesn't help I haven't done anything dealing with php in years. lol

BirdOPrey5 08-28-2010 07:11 PM

That looks right if the userid is in $userid, which I don't think it is- I think it's: $vbulletin->userinfo['userid'] , I was just using $userid as an example.

No wait that isn't right... hold on...

PHP Code:

function servicenumber($userstring)
{
if ( 
$vbulletin->userinfo['userid'] < 10) {
$userstring "000" .  $vbulletin->userinfo['userid'];
}
elseif ( 
$vbulletin->userinfo['userid'] < 100) {
$userstring "00" .  $vbulletin->userinfo['userid'];
}
elseif ( 
$vbulletin->userinfo['userid']< 1000) {
$userstring "0" .  $vbulletin->userinfo['userid'];
}  
else{
 
$userstring=strval($vbulletin->userinfo['userid']);
}
return 
$userstring;


The last else is needed if you already have a 4 digit id...

also, seems like I should point this out.... 9,999 isn't all that many userid's, if the forum ever becomes halfway popular you might easily exceed 4 digit userid's even if due only to spammers who sign up... I would seriously suggest using at least 5 if not 6 characters for this to give you some room to grow.

milla da killa 08-28-2010 07:37 PM

Quote:

Originally Posted by BirdOPrey5 (Post 2090817)
That looks right if the userid is in $userid, which I don't think it is- I think it's: $vbulletin->userinfo['userid'] , I was just using $userid as an example.

No wait that isn't right... hold on...

PHP Code:

function servicenumber($userstring)
{
if ( 
$vbulletin->userinfo['userid'] < 10) {
$userstring "000" .  $vbulletin->userinfo['userid'];
}
elseif ( 
$vbulletin->userinfo['userid'] < 100) {
$userstring "00" .  $vbulletin->userinfo['userid'];
}
elseif ( 
$vbulletin->userinfo['userid']< 1000) {
$userstring "0" .  $vbulletin->userinfo['userid'];
}  
else{
 
$userstring=strval($vbulletin->userinfo['userid']);
}
return 
$userstring;


The last else is needed if you already have a 4 digit id...

also, seems like I should point this out.... 9,999 isn't all that many userid's, if the forum ever becomes halfway popular you might easily exceed 4 digit userid's even if due only to spammers who sign up... I would seriously suggest using at least 5 if not 6 characters for this to give you some room to grow.

Of course if it ever gets that popular I'll add in an extra zero, but for the moment I don't think it's necessary. Also thanks, I'll go try this out now.

--------------- Added [DATE]1283033226[/DATE] at [TIME]1283033226[/TIME] ---------------

Weird, it's still not showing up. :/

I added it to the functions.php, and it wouldn't work, along with moving it to the functions user file, but to no avail. I truly have no clue what is going on. -.-


All times are GMT. The time now is 07:40 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.01616 seconds
  • Memory Usage 1,741KB
  • 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)bbcode_quote_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