Parse error: syntax error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Todlerone
Forum Commoner
Posts: 96
Joined: Sun Oct 28, 2007 10:20 pm
Location: Hamilton, Ontario, Canada

Parse error: syntax error

Post by Todlerone »

Hello everyone and thank-you in advance for any help/suggestions. I'm currently editing all of my baseball web site code to make it a little more streamlined (in my eyes anyway). I'm currently trying to understand classes and how to make the leap over to OOP. This code that I have pieced together from my website works where it came from but not in this form, I keep getting the Parse error on line 70. I don't see any missing "(); symbols. Any help would be appriciated

Code: Select all

<?php
function GameScoreDisplay ($type, $team){  //$type could be "thisweek, nextweek, schedule, scores, teams
    global $games, $type, $team, $dothis;
    include_once ("TCode/GamesScores.php");
    $games=find_GamesScores("hmspl", "09"); //array created in GamesScores.php
    $seasonstart = mktime( 0, 0, 0, 5, 10, 2009 )/86400;
    $seasonend = mktime( 0, 0, 0, 9, 10, 2009 )/86400;
    $seasonend2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, 2009));
    $today = date('Y-m-d');
    $now = mktime(0, 0, 0, date("m")  , date("d"), date("Y"))/86400;
    $num_games=sizeof ($games);
    
    switch ($type){
        case "thisweek":
            $dothis = "$g[5]==$week";
            $remainder= ((abs($now - $seasonstart)/7)- (floor(abs($now - $seasonstart)/7)));
            if ($remainder ==0){
                $week = abs($now - $seasonstart)/7+1;
            }elseif ($remainder >0.7){
                $week = floor(ceil(abs($now - $seasonstart)/7)+1.4);
            }else {
                $week = ceil(abs($now - $seasonstart)/7);
            }
            break;
        case "nextweek":
            $dothis = "$g[5]==$week";
            $remainder= ((abs($now - $seasonstart)/7)- (floor(abs($now - $seasonstart)/7)));
            if ($remainder ==0){
                $week = abs($now - $seasonstart)/7+2;
            }elseif ($remainder >0.7){
                $week = floor(ceil(abs($now - $seasonstart)/7)+2.4);
            }else {
                $week = ceil(abs($now - $seasonstart)/7)+1;
            }
            break;  
        case "schedule":
            $dothis = "1 == 1";  // this ok to do? Just want to enter loop
            break;
        case "scores":
            $dothis = "1 == 1";  // this ok to do? Just want to enter loop
            break;  
        case "teams":
            if (isset($team)){
                $dothis = "$g[3]==$team || $g[4]==$team";
            }
            break;  
    }           
    global $MonthNumInit==0;
    echo "<div id=\"results\">";
    echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
    foreach($games as $g):
        if ($dothis){
            global $date = $g[1];
            global $Weekday = date('D', strtotime($date));
            global $MonthNum = date ('n', strtotime($date));
            global $Dayofmonth = date ('d', strtotime($date));
            global $Monthheader = date('F', strtotime ($date));
            global $Location = $g[2];
            global $Visitor = $g[3];
            global $Home = $g[4];
            global $Weeks = $g[5];
            global $vis1=$g[6];
            global $home1=$g[7];
            global $vis2=$g[8];
            global $home2=$g[9];
            global $status1=$g[10];
            global $status2=$g[11];
            
            if ($Home == "OPN"){
                switch ($type){
                    case "schedule":
                        function schedule("showOPN");
                        break;
                    case "nextweek":
                        function schedule("showOPN");// end of season message
                        break;
                    case "thisweek":
                        if ($date < $today){
                            //do nothing
                            break;
                        }else{
                            function schedule("showOPN"); //end of season message
                        }
                        break;
                }
            }else{
                switch ($type){
                    case "schedule":
                        function schedule("showSCHEDULE");
                        break;
                    case "nextweek":
                        function schedule("showSCHEDULE");// end of season message
                        break;
                    case "thisweek":
                        function schedule("showSCORES");// needs "need scores", end of season message
                        break;
                    case "scores":
                        function schedule("showSCORES");
                        break;  
                }
            } //end ($home == "OPN")
        }
    endforeach;
}   
 
function schedule ($showthis){
        if ($MonthNum != $MonthNumInit){
            if($Monthheader == "May"){
                echo "<tr><td colspan=\"6\" bgcolor=\"#ADD8E6\">&nbsp<strong>$Monthheader</strong></td></tr>";
            }elseif ($Monthheader == "June") {
                echo "<tr><td colspan=\"6\" bgcolor=\"#999933\">&nbsp<strong>$Monthheader</strong></td></tr>";
            }elseif ($Monthheader == "July") {
                echo "<tr><td colspan=\"6\" bgcolor=\"#FF9933\">&nbsp<strong>$Monthheader</strong></td></tr>";
            }elseif ($Monthheader == "August") {
                echo "<tr><td colspan=\"6\" bgcolor=\"#66CC99\">&nbsp<strong>$Monthheader</strong></td></tr>";
            }elseif ($Monthheader == "September") {
                echo "<tr><td colspan=\"6\" bgcolor=\"#CCCC66\">&nbsp<strong>$Monthheader</strong></td></tr>";
            }
            $MonthNumInit = $MonthNum;
        }
        echo "<tr><td width=\"35\" align=\"right\">$Weekday</td>";// Mon,Tue...format
        
        if($Monthheader == "May"){
            echo "<td width=\"20\" align=\"center\"  bgcolor=\"#ADD8E6\"><strong>$Dayofmonth</strong></td>";
        }elseif ($Monthheader == "June") {
            echo "<td width=\"20\" align=\"center\" bgcolor=\"#999933\"><strong>$Dayofmonth</strong></td>";
        }elseif ($Monthheader == "July") {
            echo "<td width=\"20\" align=\"center\" bgcolor=\"#FF9933\"><strong>$Dayofmonth</strong></td>";
        }elseif ($Monthheader == "August") {
            echo "<td width=\"20\" align=\"center\" bgcolor=\"#66CC99\"><strong>$Dayofmonth</strong></td>";
        }elseif ($Monthheader == "September") {
            echo "<td width=\"20\" align=\"center\" bgcolor=\"#CCCC66\"><strong>$Dayofmonth</strong></td>";
        }
        echo "<td width=\"35\" align=\"center\">$Location</td>"; //COL, ANC, TP3 format
        
        if ($showthis == "showOPN"){
            echo "<td colspan=\"3\" align=\"center\" bgcolor=\"#66CCFF\">Open Date</td></tr>";
        }else{
            echo "<td width=\"35\" align=\"right\">$Visitor</td><td> @ </td>";
            echo "<td width=\"35\" align=\"left\">$Home</td></tr>";
        }
        
        if ($showthis == "showSCORES"){
            if (isset ($status1)){ //status1
                if ($status1=="C"){ // for completed game-1 score
                    if ($vis1>$home1){ //vis1>home1
                        echo "<tr><td colspan=\"3\" align=\"right\">1)</td><td align=\"right\"><strong>$vis1</strong></td><td>@</td><td>$home1</td></tr>";
                    }elseif ($vis1<home1){  //vis1<home1
                        echo "<tr><td colspan=\"3\" align=\"right\">1)</td><td align=\"right\">$vis1</td><td>@</td><td><strong>$home1</strong></td></tr>";
                    } else {
                        echo "<tr><td colspan=\"3\" align=\"right\">1)</td><td align=\"right\">$vis1</td><td>@</td><td>$home1</td></tr>";
                    }
                }elseif ($status1=="FV1"){
                    echo "<tr><td colspan=\"3\" align=\"right\">1)</td><td align=\"right\">(F)$vis1</td><td>@</td><td><strong>$home1</strong></td></tr>";
                }elseif ($status1=="FH1"){
                    echo "<tr><td colspan=\"3\" align=\"right\">1)</td><td align=\"right\"><strong>$vis1</strong></td><td>@</td><td>$home1(F)</td></tr>";       
                }elseif ($status1=="R1"){
                    echo "<tr><td colspan=\"3\" align=\"right\">1)</td><td colspan=\"3\" align=\"center\"><strong>Rain-Out</strong></td></tr>"; 
                }elseif ($status1=="CANC"){
                    echo "<tr><td colspan=\"3\" align=\"right\">1)</td><td colspan=\"3\" align=\"center\"><strong>Cancelled</strong></td></tr>";
                }
            }
            if ($status2=="C"){ // for completed game-2 score
                // game-2
                if ($status2=="C"){ // for completed game-2 score $g[6]=vis2...$g[7]=home2
                    if ($home2>$vis2){
                        echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td align=\"right\"><strong>$home2</strong></td><td>@</td><td>$vis2</td></tr>";
                    }elseif ($home2<$vis2){
                        echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td align=\"right\">$home2</td><td>@</td><td><strong>$vis2</strong></td></tr>";
                    } else {
                        echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td align=\"right\">$home2</td><td>@</td><td>$vis2</td></tr>";
                    }
                }elseif ($status2=="FV2"){
                    echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td align=\"right\"><strong>$home2</strong></td><td>@</td><td>$vis2(F)</td></tr>";
                }elseif ($status2=="FH2"){
                    echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td align=\"right\">(F)$home2</td><td>@</td><td><strong>$vis2</strong></td></tr>";
                }elseif ($status2=="R2"){
                    echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td colspan=\"3\" align=\"center\"><strong>Rain-Out</strong></td></tr>";
                }elseif ($status2=="D2"){
                    echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td colspan=\"3\" align=\"center\"><strong>Darkness</strong></td></tr>";     
                }elseif ($status2=="CANC"){
                    echo "<tr><td colspan=\"3\" align=\"right\">2)</td><td colspan=\"3\" align=\"center\"><strong>Cancelled</strong></td></tr>";
                }
            }
        }//end ($showthis == "showSCORES")
}//end function schedule
?>
User avatar
sergio-pro
Forum Commoner
Posts: 88
Joined: Sat Dec 27, 2008 12:26 pm

Re: Parse error: syntax error

Post by sergio-pro »

Hi

What I've found here:

1.

Code: Select all

 
global $MonthNumInit==0;
should be:
global $MonthNumInit;
$MonthNumInit=0;
 
2. Don't use global variables.
You can make a class Game that will contain fields that array $game has, and methods that calculate and retun $Weekday, $MonthNum ...
Then you can pass this object to schedule() function.

3. Schedule function call should be without 'function' keyword -

Code: Select all

 
function schedule("showOPN");
should be:
schedule("showOPN");
 
4. In schedule function there is a lot of copy-paste.

Code: Select all

 
Instead of 
            if($Monthheader == "May"){
                echo "<tr><td colspan=\"6\" bgcolor=\"#ADD8E6\">&nbsp<strong>$Monthheader</strong></td></tr>";
            }elseif ($Monthheader == "June") {
                echo "<tr><td colspan=\"6\" bgcolor=\"#999933\">&nbsp<strong>$Monthheader</strong></td></tr>";
            }elseif ... 
 
You can make an array:
$monHeaderColor = array( 
  "May" => "ADD8E6", 
  "June" => "999933",
...
);
 
and one line output:
echo "<tr><td colspan=\"6\" bgcolor=\"#". $monHeaderColor[$Monthheader] ."\">&nbsp<strong>$Monthheader</strong></td></tr>";
 
 
Hope this helps )
Todlerone
Forum Commoner
Posts: 96
Joined: Sun Oct 28, 2007 10:20 pm
Location: Hamilton, Ontario, Canada

Re: Parse error: syntax error

Post by Todlerone »

That's what I'm talking about. TY TY TY sergio-pro. That is how I want to improve and learn. I'm actually attempting the class solution for this right now. Being that I have never OOP before I'm moving forward slowly.

Cheers to you.
Post Reply