+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
Coding Thread, conditional format in php in Coding and Web Development; I have created a gaming roster system for e107 cms, and I want to see if anyone can help me ...
  1. #1

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422

    conditional format in php

    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_plugin...nfo.php?m_id=2

  2. #2

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    *update* could I use timediff sql functions?

  3. #3
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    21
    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
    Last edited by Shane; 5th January 2010 at 02:28 PM.

  4. #4

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    thanks

    that code makes it show up as "array" when its input

  5. #5
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    21
    I shall see if I can get something tested and working

  6. #6

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    many thanks!

  7. #7
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    21
    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

  8. #8

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    still shows up as array, perhaps if i gave you the file so you can see what is going on all over?

  9. #9

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,401
    Thank Post
    637
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    319
    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:

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

    Code:
    $str .= $years . ' ' . (($years > 1) ? 'years' : 'year') . ', ';
    Put that function somewhere accessible from your own code, and you should be good to go.

  10. #10

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    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

  11. #11

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    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
    Attached Files Attached Files

  12. #12
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    21
    Are you echoing the contents of $text and not $timeinegrade still?

    I think Webmans approach is far tidier and workable than mine

  13. #13

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    i set it back to the default code.

  14. #14

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,768
    Thank Post
    1,623
    Thanked 1,877 Times in 1,395 Posts
    Blog Entries
    2
    Rep Power
    422
    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!

  15. #15

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,401
    Thank Post
    637
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    319
    Quote Originally Posted by nephilim View Post
    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?

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [MS Office - 2003] Conditional Formatting
    By stevenwba in forum Office Software
    Replies: 3
    Last Post: 17th December 2009, 02:28 PM
  2. PHP Conditional Replace
    By danIT in forum Coding
    Replies: 5
    Last Post: 19th May 2009, 10:04 PM
  3. [MS Office - 2003] Access - Conditional Macros
    By garethedmondson in forum Office Software
    Replies: 5
    Last Post: 27th January 2009, 12:06 AM
  4. Help with conditional formatting
    By randle in forum Windows
    Replies: 3
    Last Post: 25th October 2007, 01:20 PM
  5. Office 2007 file format support in Apache, PHP and Moodle
    By Geoff in forum Virtual Learning Platforms
    Replies: 2
    Last Post: 8th July 2007, 12:12 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •