Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-23-2008, 02:29 PM   PM User | #1
Budde
New Coder

 
Join Date: Aug 2007
Location: New York State
Posts: 97
Thanks: 28
Thanked 1 Time in 1 Post
Budde is an unknown quantity at this point
Whats Wrong? Error...

Here's the error I am getting:

Quote:
Parse error: syntax error, unexpected $end on line 28
Here is the PHP Code:

As you can see, it is suppose to show an image that will allow people to popup a chat to listen to a live podcast/show, at given times of given days.

PHP Code:
<?php
//Get the current hour (1-24) / Date
$time date('H');
$day date('D');

//Show Name is Live (16-18 on Mons-Weds & Fridays)
if($time 16 and $time 18 && $day Monday and $day Wednesday and $day Friday ) {
   
//Live Code
   
echo 'Live Now - Image/Popup Link goes here for Chat';
}
//Show Name is Live (19-20 on Wednesdays)
if($time 19 and $time 20 && $day Wednesday){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
//Show Name is Live (16 - 18 on Thursdays)
if($time 16 and $time 18 && $day Thursday){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
//Show Name is Live (20-22 on Fridays)
if($time 20 and $time 22 && $day Friday){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
//Otherwise, We're Offair
}else{
    
//Offair Code
    
echo 'We are Currently offair. PopUp Link is here - Offair Chat... ';
}
?>
Budde is offline   Reply With Quote
Old 07-23-2008, 02:40 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Try this
PHP Code:
<?php
//Get the current hour (1-24) / Date
$time date('H');
$day date('D');
$daynum intval(date('N')); // need this to return an int

//Show Name is Live (16-18 on Mons-Weds & Fridays)
if($time == 16 && $time 18 && (($day == 'Mon' and $daynum 3) || $day == 'Fri') ) {
   
//Live Code
   
echo 'Live Now - Image/Popup Link goes here for Chat';
}
//Show Name is Live (19-20 on Wednesdays)
if($time == 19 && $time 20 && $day == 'Wed'){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
}
//Show Name is Live (16 - 18 on Thursdays)
if($time == 16 && $time 18 && $day == 'Thu'){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
}
//Show Name is Live (20-22 on Fridays)
if($time == 20 && $time 22 && $day == 'Fri'){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
//Otherwise, We're Offair
}else{
    
//Offair Code
    
echo 'We are Currently offair. PopUp Link is here - Offair Chat... ';
}
?>
Your first if statement is lacking some logic. $day returns a string and you are trying use a < operator but because they aren't numbers it will fail. You also need to be using == to compare numbers and string. I think you need to use && as well. You may be able to use AND not sure.

$day will also never return any of the days you are comparing so it will always be offline. You need to compare to the first 3 letters. Your first if statement will never be true as it can't be Monday AND Friday at the same time.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||

Last edited by _Aerospace_Eng_; 07-23-2008 at 02:44 PM..
_Aerospace_Eng_ is offline   Reply With Quote
Users who have thanked _Aerospace_Eng_ for this post:
Budde (07-23-2008)
Old 07-23-2008, 02:42 PM   PM User | #3
Budde
New Coder

 
Join Date: Aug 2007
Location: New York State
Posts: 97
Thanks: 28
Thanked 1 Time in 1 Post
Budde is an unknown quantity at this point
One question - How come when I put a link such as

Code:
<a href="#webClient" onclick="window.open('link to chat', 'Web Client','width=800,height=600,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=1')"><img src="link to image"></a>
it errors out?

Error:

Quote:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on line 9
PHP Code:

PHP Code:
 <?php
//Get the current hour (1-24) / Date
$time date('H');
$day date('D');
$daynum intval(date('N')); // need this to return an int

//Show Name is Live (16-18 on Mons-Weds & Fridays)
if($time == 16 && $time 18 && (($day == 'Mon' and $daynum 3) || $day == 'Fri') ) {
   
//Live Code
   
echo '<a href="#webClient" onclick="window.open('link to chat', 'Web Client','width=800,height=600,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=1')"><img src="link to image"></a>';
}
//Show Name is Live (19-20 on Wednesdays)
if($time == 19 && $time 20 && $day == 'Wed'){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
}
//Show Name is Live (16 - 18 on Thursdays)
if($time == 16 && $time 18 && $day == 'Thu'){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
}
//Show Name is Live (20-22 on Fridays)
if($time == 20 && $time 22 && $day == 'Fri'){
   
//Live Code
    
echo 'Live Now - Image/Popup Link goes here for Chat';
//Otherwise, We're Offair
}else{
    
//Offair Code
    
echo 'We are Currently offair. PopUp Link is here - Offair Chat... ';
}
?>
Thanks. It worked.. btw, my first written full PHP script.


Thanks for the help!

Budde

Last edited by Budde; 07-23-2008 at 02:50 PM..
Budde is offline   Reply With Quote
Old 07-23-2008, 02:45 PM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
I suggest you reread my post again. Its been edited. There are some flaws in your code.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 07-23-2008, 02:48 PM   PM User | #5
Blaher
Regular Coder

 
Join Date: Nov 2005
Location: North Canton, Ohio
Posts: 117
Thanks: 11
Thanked 4 Times in 4 Posts
Blaher is an unknown quantity at this point
First off, you might want to learn if syntax, '=' makes that variable equal that value, '==' compares the two values.

Also, as far as I know, 'and' is not logical operator. You might want to use '&&' instead.

Here's a list of operators you'll probably always use:
http://www.w3schools.com/PHP/php_operators.asp

EDIT: Opps, I waited a little too long to hit post, aero already got it.
Blaher is offline   Reply With Quote
Old 07-23-2008, 02:52 PM   PM User | #6
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
You can use and, just looked it up

http://us.php.net/manual/en/language...rs.logical.php

As to your next question as to why it errors out you need to escape your quotes. Look at the 4th example for echo on php.net
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 07-23-2008, 02:52 PM   PM User | #7
Budde
New Coder

 
Join Date: Aug 2007
Location: New York State
Posts: 97
Thanks: 28
Thanked 1 Time in 1 Post
Budde is an unknown quantity at this point
Quote:
Originally Posted by _Aerospace_Eng_ View Post
I suggest you reread my post again. Its been edited. There are some flaws in your code.
Thanks, again! I just updated my post as well... Not sure why it error out on that. See...

Edit: Oops! He got it before I got to post this
Budde is offline   Reply With Quote
Old 07-23-2008, 02:52 PM   PM User | #8
Blaher
Regular Coder

 
Join Date: Nov 2005
Location: North Canton, Ohio
Posts: 117
Thanks: 11
Thanked 4 Times in 4 Posts
Blaher is an unknown quantity at this point
You need to use \' or else it will actually end the string.

EDIT: You're too fast aero
Blaher is offline   Reply With Quote
Old 07-23-2008, 02:58 PM   PM User | #9
Budde
New Coder

 
Join Date: Aug 2007
Location: New York State
Posts: 97
Thanks: 28
Thanked 1 Time in 1 Post
Budde is an unknown quantity at this point
Thanks for your Posts, Aero and Blaher!

Oh Man! Aero is super fast at typing then!
Budde is offline   Reply With Quote
Old 07-23-2008, 03:37 PM   PM User | #10
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
unexpected $end means your missing a closing bracket }
masterofollies is offline   Reply With Quote
Old 07-24-2008, 02:12 PM   PM User | #11
Budde
New Coder

 
Join Date: Aug 2007
Location: New York State
Posts: 97
Thanks: 28
Thanked 1 Time in 1 Post
Budde is an unknown quantity at this point
How come it is always showing:

Quote:
We are Currently offair. PopUp Link is here - Offair Chat...
It never shows what the live section is set to say when it is that time and day.


Hope you can help - Thanks!

Budde
Budde is offline   Reply With Quote
Old 07-24-2008, 03:27 PM   PM User | #12
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Try changing this
PHP Code:
$time date('H'); 
to
PHP Code:
$time intval(date('H')); 
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 07-24-2008, 04:08 PM   PM User | #13
Budde
New Coder

 
Join Date: Aug 2007
Location: New York State
Posts: 97
Thanks: 28
Thanked 1 Time in 1 Post
Budde is an unknown quantity at this point
Quote:
Originally Posted by _Aerospace_Eng_
Try changing this
PHP Code:
$time date('H'); 
to
PHP Code:
$time intval(date('H')); 
Didn't work.. Still getting:

Quote:
We are Currently offair. PopUp Link is here - Offair Chat...
Budde is offline   Reply With Quote
Old 07-24-2008, 04:50 PM   PM User | #14
chaosprime
Regular Coder

 
Join Date: Apr 2008
Location: New Jersey
Posts: 116
Thanks: 0
Thanked 29 Times in 29 Posts
chaosprime is an unknown quantity at this point
You don't need to use intval. If you compare a numeric string, it'll be handled fine.

Your problem appears to be extensive logic errors. For instance, why are you doing this?

PHP Code:
if($time == 20 && $time 22 && $day == 'Fri'){ 
If $time is 20 then you already know that it's less than 22. Do you possibly mean this?

PHP Code:
if($time >= 20 && $time 22 && $day == 'Fri'){ 
__________________
Chaos
Lost Souls: text based RPG | MUDseek: MUD gaming search | MUDfind: MUD resource sites | Discordian Quotes
chaosprime is offline   Reply With Quote
Old 07-24-2008, 05:20 PM   PM User | #15
Budde
New Coder

 
Join Date: Aug 2007
Location: New York State
Posts: 97
Thanks: 28
Thanked 1 Time in 1 Post
Budde is an unknown quantity at this point
Quote:
You don't need to use intval. If you compare a numeric string, it'll be handled fine.

Your problem appears to be extensive logic errors. For instance, why are you doing this?

PHP Code:
if($time == 20 && $time 22 && $day == 'Fri'){ 
If $time is 20 then you already know that it's less than 22. Do you possibly mean this?

PHP Code:
if($time >= 20 && $time 22 && $day == 'Fri'){ 
Yes, That possibly is the code I should be using - Tested.. And results below.

Here is the Code I am using now:

PHP Code:
<?php
//Get the current hour (1-24) / Date
$time date('H'); 
$day date('D');
$daynum intval(date('N')); // need this to return an int

//Show Name is Live (16-18 on Mons-Weds & Fridays)
if($time >= 16 && $time 18 && (($day == 'Mon' and $daynum 3) || $day == 'Fri') ) {
   
//Live Code
   
echo '<br/><h2>Live</h2><br/><a href="#webClient" onclick="window.open(\'/path/to/webchat\', \'Web Client\',\'width=800,height=600,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=1\')"><img src="/path/to/image"></a></br>... You can also use our Community Chat (Coming Soon!).';
}
//Show Name is Live (19-20 on Wednesdays)
if($time >= 19 && $time 20 && $day == 'Wed'){
   
//Live Code
   
echo '<br/><h2>Live</h2><br/><a href="#webClient" onclick="window.open(\'/path/to/webchat\', \'Web Client\',\'width=800,height=600,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=1\')"><img src="/path/to/image"></a></br>... You can also use our Community Chat (Coming Soon!).';
}
//Show Name is Live (16 - 18 on Thursdays)
if($time >= 16 && $time 18 && $day == 'Thu'){
   
//Live Code
   
echo '<br/><h2>Live</h2><br/><a href="#webClient" onclick="window.open(\'/path/to/webchat\', \'Web Client\',\'width=800,height=600,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=1\')"><img src="/path/to/image"></a></br>... You can also use our Community Chat (Coming Soon!).';
}
//Show Name is Live (20-22 on Fridays)
 
if($time >= 20 && $time 22 && $day == 'Fri'){  
   
//Live Code
   
echo '<br/><h2>Live</h2><br/><a href="#webClient" onclick="window.open(\'/path/to/webchat\', \'Web Client\',\'width=800,height=600,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=1\')"><img src="/path/to/image"></a></br>... You can also use our Community Chat (Coming Soon!).';
//Otherwise, We're Offair
}else{
    
//Offair Code
    
echo 'We are Currently offair. Chat with the Community using the Community Chat. <center><strong>(Coming Soon!)</strong></center> ';
}
?>
Still getting:
Quote:
We are Currently offair. Chat with the Community using the Community Chat. (Coming Soon!)
Budde is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:27 AM.


Advertisement
Log in to turn off these ads.