View Full Version : Userid into an interval
milla da killa
08-28-2010, 04:00 PM
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, 04: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, 04:52 PM
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, 08: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...
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, 08:37 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...
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 1283033226 at 1283033226 ---------------
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. -.-
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.