TinyPortal

Development => Support => Topic started by: saffz on July 25, 2011, 03:09:33 PM

Title: Greeting Block
Post by: saffz on July 25, 2011, 03:09:33 PM
SMF version: SMF ver. 2.0 RC3
TP version: TP ver. 1.104

As you can see from image below the words Afternoon and admin are joined as one word
What do I need to do correct this?  below is the code I am using
any help would be much appreciated

Thanks

  global $user_info;

$hour = date('G') + $user_info['time_offset'];
  if ($hour > 23) { $hour = $hour - 24; }
  elseif ($hour < 0) { $hour = $hour + 24; }
  echo '<span style="text-align:center;">';

if($hour >= 0 && $hour <= 5)
{
        echo 'You are up early' . $user_info['username'] . '!';
}
else if($hour >= 6 && $hour <= 8)
{
        echo 'Grab your coffee yet' . $user_info['username'] . '!';
}
else if($hour <= 9 && $hour <= 12)
{
        echo 'Good morning' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
        echo 'Good afternoon' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
        echo 'Good evening' .  $user_info['username'] . '!';
}
        echo '</span>';


Title: Re: Greeting Block
Post by: lurkalot on July 25, 2011, 03:44:10 PM
Dunno if this is the right way to fix it,  I'm useless at code. 

but this works for me.


  global $user_info;

$hour = date('G') + $user_info['time_offset'];
  if ($hour > 23) { $hour = $hour - 24; }
  elseif ($hour < 0) { $hour = $hour + 24; }
  echo '<span style="text-align:center;">';

if($hour >= 0 && $hour <= 5)
{
        echo 'You are up early ' . $user_info['username'] . '!';
}
else if($hour >= 6 && $hour <= 8)
{
        echo 'Grab your coffee yet ' . $user_info['username'] . '!';
}
else if($hour <= 9 && $hour <= 12)
{
        echo 'Good morning ' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
        echo 'Good afternoon ' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
        echo 'Good evening ' .  $user_info['username'] . '!';
}
        echo '</span>';
Title: Re: Greeting Block
Post by: saffz on July 25, 2011, 03:59:05 PM
Quote from: lurkalot on July 25, 2011, 03:44:10 PM
Dunno if this is the right way to fix it,  I'm useless at code. 

but this works for me.


  global $user_info;

$hour = date('G') + $user_info['time_offset'];
  if ($hour > 23) { $hour = $hour - 24; }
  elseif ($hour < 0) { $hour = $hour + 24; }
  echo '<span style="text-align:center;">';

if($hour >= 0 && $hour <= 5)
{
        echo 'You are up early ' . $user_info['username'] . '!';
}
else if($hour >= 6 && $hour <= 8)
{
        echo 'Grab your coffee yet ' . $user_info['username'] . '!';
}
else if($hour <= 9 && $hour <= 12)
{
        echo 'Good morning ' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
        echo 'Good afternoon ' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
        echo 'Good evening ' .  $user_info['username'] . '!';
}
        echo '</span>';


Shinning night in armour saves my day again, Thank you Lurkalot It works  for me too. O0
Is there a way I can Make the Text Bold?
Title: Re: Greeting Block
Post by: saffz on July 25, 2011, 04:58:51 PM
Its ok I got it .  Thanks again for your help
Title: Re: Greeting Block
Post by: Lesmond on July 25, 2011, 05:20:33 PM
Quote from: saffz on July 25, 2011, 04:58:51 PM
Its ok I got it .  Thanks again for your help

What did you do saffz? it may help other members.
Title: Re: Greeting Block
Post by: lurkalot on July 25, 2011, 05:34:15 PM
Quote from: ©Lesmond on July 25, 2011, 05:20:33 PM
Quote from: saffz on July 25, 2011, 04:58:51 PM
Its ok I got it .  Thanks again for your help

What did you do saffz? it may help other members.

Yes, like me for example. lol.. :D
Title: Re: Greeting Block
Post by: saffz on August 03, 2011, 08:25:58 AM
Quote from: ©Lesmond on July 25, 2011, 05:20:33 PM
Quote from: saffz on July 25, 2011, 04:58:51 PM
Its ok I got it .  Thanks again for your help

What did you do saffz? it may help other members.

I added the bold tag

echo '<b>Grab your coffee yet</b>' . $user_info['username'] . '!';
Title: Re: Greeting Block
Post by: saffz on August 03, 2011, 10:09:49 AM
It has stopped working, does anyone know why this would happen?
Title: Re: Greeting Block
Post by: ZarPrime on August 03, 2011, 01:42:47 PM
Well, since you are using date('G') for $hour, these 2 lines should not be necessary and might cause the php parser to get confused the way it's written ...

  if ($hour > 23) { $hour = $hour - 24; }
  elseif ($hour < 0) { $hour = $hour + 24; }


So, I would take these 2 lines out.  This is because date('G') is evaluated from 0 to 23 so there should never be an instance where $hour is less than 0 or greater than 23.

Also, you should probably switch all instances of "else if" to "elseif" in the remaining code.  Freddy, our coder could verify whether I am correct on this but I believe that if you are using "else if" statements, each one is evaluated without regard to the previous one whereas, if you use "elseif" the code will complete once the first TRUE is reached.  That means that the code will probably run better and faster using "elseif".

Next, one line in your code is using 2 instances of "<=", that being this one ...


elseif ($hour <= 9 && $hour <= 12)


That should probably be change to ...


elseif ($hour >= 9 && $hour <= 12)


Finally, the last "elseif" in the code should probably just be "else" so that code execution can stop properly.  In other words, if all the "elseif" lines are FALSE, then the last one has to be TRUE.  That could also cause a conflict.  Try this code below for a couple of days and see if it works better (You'll have to put your Bold tags back in there if you want them as I didn't put those in) ...


  global $user_info;

$hour = date('G') + $user_info['time_offset'];

echo '<span style="text-align:center;">';

if ($hour >= 0 && $hour <= 5) {
        echo 'You are up early ' . $user_info['username'] . '!';
} elseif ($hour >= 6 && $hour <= 8) {
        echo 'Grab your coffee yet ' . $user_info['username'] . '!';
} elseif ($hour >= 9 && $hour <= 12) {
        echo 'Good morning ' . $user_info['username'] . '!';
} elseif ($hour >= 13 && $hour <= 16) {
        echo 'Good afternoon ' . $user_info['username'] . '!';
} else {
        echo 'Good evening ' .  $user_info['username'] . '!';
}
        echo '</span>';


ZarPrime
Title: Re: Greeting Block
Post by: saffz on August 05, 2011, 08:54:01 PM
ZarPrime thank you for taking the time to amend this 
really appreciate all hard work you all put in the support is awsome

Thanks again

S@ffz   O0
Title: Re: Greeting Block
Post by: ZarPrime on August 05, 2011, 09:06:53 PM
saffz,

No problem.  Glad to help. O0 Did you try the code I posted above yet?  It should work just fine.  I've had it working good on a test site for the last couple of days and it's doing well so far.

ZarPrime
Title: Re: Greeting Block
Post by: saffz on August 06, 2011, 05:12:03 AM
Quote from: ZarPrime on August 05, 2011, 09:06:53 PM
saffz,

No problem.  Glad to help. O0 Did you try the code I posted above yet?  It should work just fine.  I've had it working good on a test site for the last couple of days and it's doing well so far.

ZarPrime

I sure did its working a treat  O0

Thank you
Title: Re: Greeting Block
Post by: ZarPrime on August 06, 2011, 06:27:19 PM
OK, good. O0 For now, I am going to mark this topic solved and move it to the Support Board.

Would you like to share this block code snippet with everybody?  If so, we can setup a topic in the Block Code Snippets Board for it.

ZarPrime