TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,965
  • Latest: boruko
Stats
  • Total Posts: 195,980
  • Total Topics: 21,320
  • Online today: 281
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 317
  • Total: 317

Greeting Block

Started by saffz, July 25, 2011, 03:09:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

saffz

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>';



lurkalot

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>';

saffz

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?

saffz

Its ok I got it .  Thanks again for your help

Lesmond

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.

lurkalot

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

saffz

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'] . '!';

saffz

It has stopped working, does anyone know why this would happen?

ZarPrime

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

saffz

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

This website is proudly hosted on Crocweb Cloud Website Hosting.