Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Aug 2007
    Location
    New York State
    Posts
    97
    Thanks
    28
    Thanked 1 Time in 1 Post

    Whats Wrong? Error...

    Here's the error I am getting:

    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... ';
    }
    ?>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    Last edited by _Aerospace_Eng_; 07-23-2008 at 03:44 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Budde (07-23-2008)

  • #3
    New Coder
    Join Date
    Aug 2007
    Location
    New York State
    Posts
    97
    Thanks
    28
    Thanked 1 Time in 1 Post
    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:

    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 03:50 PM.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    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.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #7
    New Coder
    Join Date
    Aug 2007
    Location
    New York State
    Posts
    97
    Thanks
    28
    Thanked 1 Time in 1 Post
    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

  • #8
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    You need to use \' or else it will actually end the string.

    EDIT: You're too fast aero

  • #9
    New Coder
    Join Date
    Aug 2007
    Location
    New York State
    Posts
    97
    Thanks
    28
    Thanked 1 Time in 1 Post
    Thanks for your Posts, Aero and Blaher!

    Oh Man! Aero is super fast at typing then!

  • #10
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    unexpected $end means your missing a closing bracket }

  • #11
    New Coder
    Join Date
    Aug 2007
    Location
    New York State
    Posts
    97
    Thanks
    28
    Thanked 1 Time in 1 Post
    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

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #13
    New Coder
    Join Date
    Aug 2007
    Location
    New York State
    Posts
    97
    Thanks
    28
    Thanked 1 Time in 1 Post
    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:

    We are Currently offair. PopUp Link is here - Offair Chat...

  • #14
    Regular Coder
    Join Date
    Apr 2008
    Location
    New Jersey
    Posts
    116
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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

  • #15
    New Coder
    Join Date
    Aug 2007
    Location
    New York State
    Posts
    97
    Thanks
    28
    Thanked 1 Time in 1 Post
    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:
    We are Currently offair. Chat with the Community using the Community Chat. (Coming Soon!)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •