Jump to content

Recommended Posts

Posted

I have created a gaming roster system for e107 cms, and I want to see if anyone can help me here. I have written up this code to show how long people have been in the clan, but I have come across a stumbling block. It shows up that if a person has been there longer than a week, it comes up as 8 days etc, and longer than 1 month it shows up as 32 days, a year shows up as 365 days etc etc.

 

I would like to know what changes I should make to this code to change it so that it shows that 7 days = 1 week, 8 days = 1 week 1 day etc. If anyone can help it would be much appreciated! Below is the code written for that particular section.

 

Many thanks

 

$time = time();

$timeingrade = ceil(($time - $member_a['roster_member_rankdate'])/(24*60*60));

if($timeingrade == 1){

$timeingrade = $timeingrade." day";

}

if($timeingrade == 1){

$timeingrade = $timeingrade." day";

}

else{

$timeingrade = $timeingrade." days";

}

 

a link to see it in action is here

 

http://www.carltest.info/e107_plugins/roster/userinfo.php?m_id=2

Posted (edited)

Maybe something like this (but will need to sort out dealing with the text if it is only 1 week or ends in 1 day):

I haven't tested any of this

 

if($timeingrade < 8){

$text = $timeingrade." days";

}elseif($timeingrade == 1){

$text = $timeingrade." day";

}elseif($timeingrade=>7){

$timeingrade = $timeingrade/7;

$timeingrade=explode(".",$timeingrade);

$text=$timeingrade[0]." Weeks and ".$timeingrade[1]." Days";

}

 

 

 

The result would be outputted to the variable $text and no longer $timeingrade

Edited by cl0n3
Posted

if($timeingrade < 8){

$text = $timeingrade." days";

}elseif($timeingrade == 1){

$text = $timeingrade." day";

}elseif($timeingrade>=7){

$timeingrade = $timeingrade/7;

$timeingrade=explode(".",$timeingrade);

$text=$timeingrade[0]." Weeks and ".$timeingrade[1]." Days";

}

 

This now seems to work yet you will have to do some rounding with the $timeingrade[1] value I think

Posted

There's a function called timespan() in the open source framework CodeIgniter that does just that. The code of which is shown here. All you should have to do is remove the $CI references, and re-work the variable assignments. The function parameters expect time to specified in integers, UNIX timestamp format.

 

For example:

 

$str .= $years.' '.$CI->lang->line((($years	> 1) ? 'date_years' : 'date_year')).', ';

 

Would be:

 

$str .= $years . ' ' . (($years > 1) ? 'years' : 'year') . ', ';

 

Put that function somewhere accessible from your own code, and you should be good to go.

Posted

Are you echoing the contents of $text and not $timeinegrade still?

 

I think Webmans approach is far tidier and workable than mine

Posted
I tried for about 3 hours, I couldnt get any of the coding to show weeks and days so I give up! But I am happy with my finished product for now! :)

 

Did you try using the function from the code I posted before?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...