Jump to content


Photo

Need some help with PHP code


  • Please log in to reply
35 replies to this topic

#21 Chaos King

Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 29 October 2006 - 05:21 PM

PHP is all about logic. If you don't have logic, you will never get anywhere.


yep, so basically what your error, this one:
( Parse error: parse error, unexpected ')' in /home/artorb5/public_html/max/ao.php on line 72 )

means that there was something wrong with the syntax itself, the actual way you wrote the code. and unexpected ')' meant that you had a close-parenthesis character that shouldn't have been there!

just to help you boost your learning curve :)


Don't worry about my learning curved, its been boosted. Why don't you try and run that code under php 5 and see? :D I don't know what problems you are having, but it is an error free snippet.

And here is another snippet for you of those who don't strive for updated techniques. :)

$d = date ( 'H' );

if ( $d > 22 )
{
	echo 'Good Night!';
}
else if ( $d > 18 )
{
	echo 'Good Evening!';
}
else if ( $d > 15 )
{
	echo 'Good Afternoon!';
}
else if ( $d > 12 )
{
	echo 'Good Day!';
}
else if ( $d > 6 )
{
	echo 'Good Morning';
}
else
{
	echo 'Hello';
}

Anyways:
@ http://www.pixel2lif...p...st&p=178938

Change it with this:
if ( $d >= 22 && $d < 6 ) {


#22 Chrypetex

Chrypetex

    Young Padawan

  • Members
  • Pip
  • 121 posts
  • Gender:Male
  • Location:Sweden
  • Interests:Photos

Posted 30 October 2006 - 07:50 AM

Thanks for you help everyone! I think that influct has right, mine server's time isn't the same as mine, so I'll try to find out their time.

Thanks for your help everyone!

#23 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 30 October 2006 - 08:30 AM

You can temporarily change server time for the length of the script you are running Chrypetex by adding this to the top of your script (before date())
putenv("TZ=Europe/Stockholm");

That should set it to your time (assuming that your profile is correct and you are in sweden).

#24 Chrypetex

Chrypetex

    Young Padawan

  • Members
  • Pip
  • 121 posts
  • Gender:Male
  • Location:Sweden
  • Interests:Photos

Posted 30 October 2006 - 08:40 AM

Thanks! The script is working completely now, anyway for those who live in Stockholm ^^

#25 influct

influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 30 October 2006 - 09:02 AM

like i suggested, use javascript to set a cookie with the time, javascript grabs the users time, not the servers time. then get php to read this cookie!

#26 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 30 October 2006 - 01:31 PM

I would love to see a number that is both greater than 22 and less than 6 at the same time. Till you prove otherwise, i'm going to say, no you can't, but you can have a number greater than 22 OR less than 6.

Honestly, i believe Chaos's code should work and we don't need a thousand different derivitives of it. Influct made the other good point that is probably the reason this topic is so long, the server time is not the same as your time unless you're running the server off your own comp, or you're really lucky.
Odds are you're going to have to adjust the time to your timezone in order for it to "work" then you'll have to adjust it to every users timezone as well (which is not easy). I say just use JS for this with a <noscript> tag to say a generalized welcome.

Edited by rc69, 30 October 2006 - 01:31 PM.


#27 influct

influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 30 October 2006 - 02:20 PM

but hours loop, so you get
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,1,2,3,4,5,6,7,8,9
,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
and so on.
to php it reads it as continuous, so in this case everything from 23 through 5 (23,24,1,2,3,4,5) is greater than 22 and less than 6:)
This does only work when talking about 24 hour time though:P

#28 cheerio

cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 30 October 2006 - 02:52 PM

but hours loop, so you get
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,1,2,3,4,5,6,7,8,9
,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
and so on.
to php it reads it as continuous, so in this case everything from 23 through 5 (23,24,1,2,3,4,5) is greater than 22 and less than 6:)
This does only work when talking about 24 hour time though:P

How does PHP "know" you are using a number loop <_< Use OR and you'll be fine

#29 influct

influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 30 October 2006 - 03:18 PM

php knows everything:P
it dosnt, it simply grabs the hour, the hour is a number loop.
If it went up to 24 and stopped we'd forever be at 24:00
and no-one wants that!

#30 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 31 October 2006 - 10:52 PM

PHP knows exactly what you let it know. To PHP time is just a number, nothing more. It is not something that loops infinitely, it is a number that grows infinately larger. Don't believe me? Echo time() for the rest of your natural life, let me know when it resets to zero.

Have you ever taken Algebra? Or better yet Algebra 2? Have you ever had to graph numbers, or equations of numbers on a number line?
Graph: 6 > x > 22. Not only is that read "x is less than 6 OR greater than 22" it does not include any number more than once.

PHP is all about logic. If you don't have logic, you will never get anywhere.

Again i pose this challenge to you. Find me a number that proves me wrong.

Edited by rc69, 31 October 2006 - 10:53 PM.


#31 Chaos King

Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 31 October 2006 - 11:08 PM

Are you challenging me? Or Him? Or are you quoting me. I am confused. If you are challenging me, so be it. Bring it on. People just don't realize that if you think like your script, coding will be easier and if you read what you are writing, you would find all your logic right there.

#32 Chrypetex

Chrypetex

    Young Padawan

  • Members
  • Pip
  • 121 posts
  • Gender:Male
  • Location:Sweden
  • Interests:Photos

Posted 01 November 2006 - 09:04 AM

like i suggested, use javascript to set a cookie with the time, javascript grabs the users time, not the servers time. then get php to read this cookie!


Yea, But it sounds so... Complicated, how shouldI make it? O_o

#33 influct

influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 01 November 2006 - 11:38 AM

1 aclock (01:00) in the morning, surely this is after 10 aclock (20:00) in the evening the previous day but before 6 oclock (6:00) that will happen later that day?

#34 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 01 November 2006 - 07:30 PM

Are you challenging me? Or Him? Or are you quoting me. I am confused. If you are challenging me, so be it. Bring it on. People just don't realize that if you think like your script, coding will be easier and if you read what you are writing, you would find all your logic right there.

Quoting you, challenging him, but you're welcome to join in on the fun. Amen to the rest that...

1 aclock (01:00) in the morning, surely this is after 10 aclock (20:00) in the evening the previous day but before 6 oclock (6:00) that will happen later that day?

That might be right, but you've yet to give me a single number that is less than six and greater than 22. Just one number, that's all i ask for, not a time.

like i suggested, use javascript to set a cookie with the time, javascript grabs the users time, not the servers time. then get php to read this cookie!


Yea, But it sounds so... Complicated, how shouldI make it? O_o

You're right, it is complicated. To complicated. So simplify, if php won't do what you want because of time zones, do what i said and use just JS.
<html>
<head>
<title>Page</title>
</head>

<body>
<script type="text/javascript">
// Note: i've never used the date object, so i'll provide a "rough draft"
//	   then somebody can clean up my mess.
var hour = new Date('H'); // Get the hour of the day.
var message;
if(hour > 22 ){
	message = 'Good Night!';
}else if(hour > 18 ){
	message = 'Good Evening!';
}else if(hour > 15 ){
	message = 'Good Afternoon!';
}else if(hour > 12 ){
	message = 'Good Day!';
}else if(hour > 6 ){
	message = 'Good Morning';
}else{
	message = 'Hello';
}

document.write(message);
</script>

<noscript>Hello</noscript>
</body>
</html>


#35 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 01 November 2006 - 07:46 PM

rc i don't think (but im not good at js so dont shoot me) that yours will work. The date object to my knowledge doesn't take parameters like that.

This is how i would do it:
var time = new Date // new Date object
var hour = time.getHours() // getHours returns values 0-23

var message;
if(hour > 22 ){
	message = 'Good Night!';
}else if(hour > 18 ){
	message = 'Good Evening!';
}else if(hour > 15 ){
	message = 'Good Afternoon!';
}else if(hour > 12 ){
	message = 'Good Day!';
}else if(hour > 6 ){
	message = 'Good Morning';
}else{
	message = 'Hello';
}

alert('Hour is: ' + hour + '\nWelcome message is: ' + message); // just check it works o__0

Without testing it, i think that will work.

Edited by Matthew., 01 November 2006 - 07:50 PM.


#36 influct

influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 02 November 2006 - 11:59 AM

touche (i know the e is accented:P) there is no number smaller than six but greater than 22, but when your talking about hours then technically there is.
Or at least you describe it as being after 22 hours but before 6 hours.
maybe that makes a bit more sense:P




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users