Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-28-2010, 04:00 PM
milla da killa milla da killa is offline
 
Join Date: Jul 2008
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 08-28-2010, 04:26 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #3  
Old 08-28-2010, 04:52 PM
milla da killa milla da killa is offline
 
Join Date: Jul 2008
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 08-28-2010, 08:11 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 08-28-2010, 08:37 PM
milla da killa milla da killa is offline
 
Join Date: Jul 2008
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by BirdOPrey5 View Post
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. -.-
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:23 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08227 seconds
  • Memory Usage 2,218KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete