• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Trying show VIP Status at website

Status
Not open for further replies.

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hello everyone, it suppost to works like if > 366 days then says infinite, if < 365 then tells says the days left and if it's equal 0 then says free account, but check the image below. Account has been set with 0 vipdays.

FLwdpWyPn.png


Code:
$dataAtual = time();
             $dataProxima = $account_logged->getCustomField('vipdays');
             $data1 = $dataProxima - $dataAtual;
             $dataCerta = $data1 / 86400;
             if($account_logged->getCustomField('vipdays') > 366)
               ECHO '<td>Infinite</td>';
             if($account_logged->getCustomField('vipdays') < 365)
               ECHO '<td>'. floor($dataCerta) .'</td>';
             if($account_logged->getCustomField('vipdays') == 0)
               ECHO '<td>Free Account</td>';

Thanks.
 
PHP:
    date_default_timezone_set('UTC');
    $vipDays = intval(date('z', time() - $account_logged->getCustomField('vipdays')));
    switch($vipDays){
        case $vipDays > 365 :
            echo '<td>Infinite</td>';
            break;
        case $vipDays <= 365 && $vipDays > 0 :
            echo '<td>'. $vipDays .'</td>';
            break;
        default:
            echo '<td>Free Account</td>';
            break;
    }

Edit: I keep editing it...

The only thing you need to edit is this section of the code, + or - .
PHP:
time() - $account_logged->getCustomField('vipdays')
 
Last edited:
@Codex NG
It keep saying "343" with account been seted with 0 vipdays.

#edit
With the code below it keep telling "Infinite" with 0 vipdays.
Code:
$vipDays = $account_logged->getCustomField('vipdays');
             switch($vipDays){
               case $vipDays > 365 :
                 echo '<td>Infinite</td>';
                 break;
               case $vipDays <= 365 && $vipDays > 0 :
                 echo '<td>'. $vipDays .'</td>';
                 break;
               default:
                 echo '<td>Free Account</td>';
                 break;
             }
 
The issue with your code what that you are 1) not using elseifs 2) checking for $vipdays == 0 last

Code:
$dataAtual = time();
$dataProxima = $account_logged->getCustomField('vipdays');
$data1 = $dataProxima - $dataAtual;
$dataCerta = $data1 / 86400;
$vipdays = $account_logged->getCustomField('vipdays');

if($vipdays == 0)
    echo '<td>Free Account</td>';
elseif($vipdays > 365)
    echo '<td>Infinite</td>';
elseif($vipdays <= 365)
    echo '<td>'. floor($dataCerta) .'</td>';

@Codex NG
That's not how switch case should be used.
 
It's mainly wrong because it does not work. It prints the correct result for 2 of 3 cases by accident, but fails for $vipDays = 0.
It works if you add "case 0:" instead of "default:" and move it to the first position, but then it's look really ugly.

Case 1:
Code:
$vipDays = 0;

switch($vipDays) {
  case $vipDays > 365 :  // expression evaluates to false, 0 is also evaluated to false => "$vipDays = 0" prints "Infinite"
    echo '<td>Infinite</td>';
    break;
  case $vipDays <= 365 && $vipDays > 0 : // expression evaluates to false
    echo '<td>'. $vipDays .'</td>';
    break;
  default:
    echo '<td>Free Account</td>';
    break;
}


Case 2:
Code:
$vipDays = 1;

switch($vipDays) {
  case $vipDays > 365 :  // expression evaluates to false
    echo '<td>Infinite</td>';
    break;
  case $vipDays <= 365 && $vipDays > 0 : // expression evaluates to true, 1 is also evaluated to true => "$vipDays = 1" prints "1"
    echo '<td>'. $vipDays .'</td>';
    break;
  default:
    echo '<td>Free Account</td>';
    break;
}


Case 3:
Code:
$vipDays = 366;

switch($vipDays) {
  case $vipDays > 365 :  // expression evaluates to true, 366 is also evaluated to true => "$vipDays = 366" prints "Infinite"
    echo '<td>Infinite</td>';
    break;
  case $vipDays <= 365 && $vipDays > 0 : // expression evaluates to false
    echo '<td>'. $vipDays .'</td>';
    break;
  default:
    echo '<td>Free Account</td>';
    break;
}
 
It's mainly wrong because it does not work. It prints the correct result for 2 of 3 cases by accident, but fails for $vipDays = 0.
It works if you add "case 0:" instead of "default:" and move it to the first position, but then it's look really ugly.
I don't see anywhere in the code an issue,
If vipDays > 365 it chooses the 1st, if its less or equal to 365 and greater than 0 then it uses that case.
If vipDays == 0 or lower for whatever reason it reverts to default, which prints free account to the screen.
What do you think default is for?

You know what is messy? A bunch of if or if/else statements.
 
I did not take the time and put comments in the code for you to ignore those. Take your time and read them.
Switch case does not work how you claim that it does.
 
Status
Not open for further replies.
Back
Top