I am working with two seperate files which contain similar code - One throws a parse error for an identical line, the other does not. I do not understand why this would be.

The error on the file that will not run is: Parse error: syntax error, unexpected '2' (T_LNUMBER)

Here is a code snippet that works without the parse error:

if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; } echo '<tr '.$rowClass.'>';

Here is a code snippet that does not work and has the parse error:

if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; } echo '<tr '.$rowClass.'>';

Identical.

This error centers around the use of the 2, hence the (T_LNUMBER).

I see no difference in either code - I am simply doing ($indx % 2) == 1), the 2 being the problem for some reason.

Thank you in advance for any help!

Recommended Answers

All 3 Replies

what's the rest of the error message

also post more of the code around the erroring line

Hi,

The complete error message is: Parse error: syntax error, unexpected '2' (T_LNUMBER) in C:\xampp\htdocs\demo\nest_Demo_thrasher.php on line 115

The full code for the file in question:

<?php
/*

*   File:       nest_Demo.php
*   By:         TMIT
*   Date:       2010-06-01
*
*   This script demonstrates elegant nested rendering
*       using SQL rather than a language construct
*       
*
*=========================================================================
*/

{       //  Secure Connection Script
        include('../../htconfig/dbConfig.php'); 
        $dbSuccess = false;
        $dbConnected =    mysql_connect($db['hostname'],$db['username'],$db['password']);

        if ($dbConnected) {     
            $dbSelected = mysql_select_db($db['database'],$dbConnected);
            if ($dbSelected) {
                $dbSuccess = true;
            } else {
                echo "DB Selection FAILed";
            }
        } else {
                echo "MySQL Connection FAILed";
        }
        //  END Secure Connection Script
}

if ($dbSuccess) {

    {  //   Style declarations
            $trOdd = 'style = "background-color: #BFFFCF;"';
            $trEven = 'style = "background-color: #FCCDFF;"';

            $textFont = 'style = " font-family: arial, helvetica, sans-serif; "';
            $textRed = 'style = " font-family: arial, helvetica, sans-serif; color:maroon; "';

            $indent50 = 'style = " margin-left: 50; "';
            $indent100 = 'style = " margin-left: 100; "';

    //   END: Style declarations    
    }

    echo '<h1>All Persons by Company</h1>';

    {   //      SQL
    $tPerson_SQLselect = "SELECT  ";
    $tPerson_SQLselect .= "tPerson.ID AS personID, ";   
    $tPerson_SQLselect .= "tPerson.Salutation, ";   
    $tPerson_SQLselect .= "tPerson.FirstName, tPerson.LastName, ";  



    $tPerson_SQLselect .= "tCompany.ID AS companyID, ";     
    $tPerson_SQLselect .= "tCompany.preName, tCompany.Name, tCompany.RegType "; 
    $tPerson_SQLselect .= "FROM tPerson LEFT JOIN tCompany ";
    $tPerson_SQLselect .= "ON tPerson.CompanyID = tCompany.ID ";
    $tPerson_SQLselect .= "ORDER BY tCompany.Name, tCompany.preName, tCompany.ID, ";
    $tPerson_SQLselect .= "tPerson.LastName, tPerson.FirstName ";

    $tPerson_SQLselect_Query = mysql_query($tPerson_SQLselect);
    //      END:  SQL   
    }       
    $currentCompanyID = -1;
    $indx = 0;
    echo '<div '.$textFont.'>';

    while ($row = mysql_fetch_array($tPerson_SQLselect_Query, MYSQL_ASSOC)) {

            {   //  assign variables to row data 
                $personID = $row['personID'];
                $Salutation = $row['Salutation'];
                $FirstName = $row['FirstName'];
                $LastName = $row['LastName'];
                $Telephone = $row['Telephone'];
                $eMail = $row['eMail'];

                $CompanyID = $row['companyID'];
                $CompanypreName = $row['preName'];
                $CompanyName = $row['Name'];
                $CompanyRegType = $row['RegType'];

                $CompanyFullName = trim($CompanypreName." ".$CompanyName." ".$CompanyRegType);
            //  END:  assign variables to row data 
            }

            {   //      Company header 
                if (empty($CompanyID)) {
                    $CompanyID = 0;
                    $CompanyFullName = "UN-Allocated";
                }   

               if ($CompanyID <> $currentCompanyID) {

                   if ($currentCompanyID <> -1) {
                //      Render the table tail 
                        echo "</table>"; 
                        echo '</div>';
                }

                //      Render the company header
                echo '<h2 '.$indent50.'>'.$CompanyFullName.'</h2>';

                    echo '<div '.$indent100.'>';
                echo "<table border='1'>";
                    echo "<tr>";

                        echo "<td>#</td>";
                        echo "<td>Salutation</td>";
                        echo "<td>FirstName</td>";
                        echo "<td>LastName</td>";
                        echo "<td>Telephone</td>";
                        echo "<td>eMail</td>";

                    echo "</tr>";  

                //      
               } 
                    $currentCompanyID = $CompanyID;
            //  END:   Company header 
            }   

            {   //      Create and format a row for each person
            if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; }
            echo '<tr '.$rowClass.'>';


                echo "<td>".$personID."&nbsp;</td>";       //  this is NOT  tPerson.ID
                echo "<td>".$Salutation."&nbsp;</td>";
                echo "<td>".$FirstName."&nbsp;</td>";
                echo "<td>".$LastName."&nbsp;</td>";
                echo "<td>".$Telephone."&nbsp;</td>";
                echo "<td>".$eMail."&nbsp;</td>";

            echo "</tr>";
            }   //      END:  Create and format a row for each person

            $indx++;

    //     END:  while ($row = mysql_fetch_array($tPerson_SQLselect_Query
    }

    echo '</div>';

    mysql_free_result($tPerson_SQLselect_Query);        
}

?>

`

This has been solved.

It seems like it was an issue with my code editor (BlueFish) or something.

When I removed the % in ($indx % 2) == 1), saved the file, and ran it I received the same error as noted in my original post.

I then re-added % to ($indx 2) == 1), saved it, ran it and it worked.

Not sure what happened there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.