featured_spectre Posted January 5, 2010 Posted January 5, 2010 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
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 *update* could I use timediff sql functions?
cl0n3 Posted January 5, 2010 Posted January 5, 2010 (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 January 5, 2010 by cl0n3
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 thanks that code makes it show up as "array" when its input
cl0n3 Posted January 5, 2010 Posted January 5, 2010 I shall see if I can get something tested and working
cl0n3 Posted January 5, 2010 Posted January 5, 2010 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
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 still shows up as array, perhaps if i gave you the file so you can see what is going on all over?
webman Posted January 5, 2010 Posted January 5, 2010 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.
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 still shows up as array...this is getting frustrating. Whilst I dont mind it saying X has been at such a place for 745 days, it does look a bit unprofessional
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 I have attached the file to this page... if you can take a good look at the whole thing to be sure I am not going nuts. lol
cl0n3 Posted January 5, 2010 Posted January 5, 2010 Are you echoing the contents of $text and not $timeinegrade still? I think Webmans approach is far tidier and workable than mine
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 i set it back to the default code.
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 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!
webman Posted January 5, 2010 Posted January 5, 2010 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?
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 yeah, it kept coming up as "array" no matter which way I tried.
webman Posted January 5, 2010 Posted January 5, 2010 That sounds strange. There's no references to arrays anywhere in that function.
featured_spectre Posted January 5, 2010 Author Posted January 5, 2010 as I know, but thats what is coming up, its very odd
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now