Budde 07-23-2008, 02:29 PM Here's the error I am getting:
Parse error: syntax error, unexpected $end on line 28Here 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
//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... ';
}
?>
_Aerospace_Eng_ 07-23-2008, 02:40 PM Try this
<?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.
Budde 07-23-2008, 02:42 PM One question - How come when I put a link such as
<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:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on line 9PHP 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
_Aerospace_Eng_ 07-23-2008, 02:45 PM I suggest you reread my post again. Its been edited. There are some flaws in your code.
Blaher 07-23-2008, 02:48 PM 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.
_Aerospace_Eng_ 07-23-2008, 02:52 PM You can use and, just looked it up
http://us.php.net/manual/en/language.operators.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
Budde 07-23-2008, 02:52 PM 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... (http://codingforums.com/showpost.php?p=715446&postcount=3)
Oops! He got it before I got to post this
Blaher 07-23-2008, 02:52 PM You need to use \' or else it will actually end the string.
EDIT: You're too fast aero
Budde 07-23-2008, 02:58 PM Thanks for your Posts, Aero and Blaher!
Oh Man! Aero is super fast at typing then! ;)
masterofollies 07-23-2008, 03:37 PM unexpected $end means your missing a closing bracket }
Budde 07-24-2008, 02:12 PM How come it is always showing:
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
_Aerospace_Eng_ 07-24-2008, 03:27 PM Try changing this
$time = date('H');
to
$time = intval(date('H'));
Budde 07-24-2008, 04:08 PM Try changing this
$time = date('H');to
$time = intval(date('H'));
Didn't work.. Still getting:
We are Currently offair. PopUp Link is here - Offair Chat...
chaosprime 07-24-2008, 04:50 PM 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?
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?
if($time >= 20 && $time < 22 && $day == 'Fri'){
Budde 07-24-2008, 05:20 PM 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?
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?
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
//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:
We are Currently offair. Chat with the Community using the Community Chat. (Coming Soon!)
chaosprime 07-24-2008, 05:25 PM From your comments, you probably also mean <= rather than < on the various conditions.
($day == 'Mon' and $daynum < 3) is also nonsensical.
I really just think you need to thoroughly go over your own logic and think about whether what you're telling the computer to do is what you actually mean.
|
|