-2

I have the error PHP Parse error: syntax error, unexpected 'else' (T_ELSE)" on line 97. I already checked the brackets for many times and seems like all the brackets are fine. Can anyone recheck my code and show me if I've missed anything in the code?

Here is my code:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="http://www.cssscript.com/wp-includes/css/sticky.css" rel="stylesheet" type="text/css">
    <link href="Style.css" rel="stylesheet" type="text/css">
    <title>MS BPR organization chart</title>
    <?php


    ini_set('display_errors', 1);

    ini_set('display_startup_errors', 1);

    error_reporting(E_ALL);


    include 'DBcon.php';

    ?>
</head>

<body>
<div id="css-script-menu">
    <div class="css-script-center">
        <ul>
            <li><a href="http://www.cssscript.com/responsive-hierarchical-organization-chart-pure-css/">Download</a>
            </li>
            <li><a href="http://www.cssscript.com/">Back To CSS Script</a></li>
        </ul>
        <div class="css-script-ads">
            <script type="text/javascript"><!--
                google_ad_client = "ca-pub-2783044520727903";
                /* CSSScript Demo Page */
                google_ad_slot = "3025259193";
                google_ad_width = 728;
                google_ad_height = 90;
                //-->
            </script>
            <script type="text/javascript"
                    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
            </script>
        </div>
        <div class="css-script-clear"></div>
    </div>
</div>
<div id="wrapper">
    <div id="container">
        <h1>MS BPR Organization Chart</h1>
        <ol class="organizational-chart">
            <li>
                <?php

                //Print all items from database.
                $query = "SELECT * FROM [MSBPR].[dbo].[MSTeam] ORDER BY Position,MSGroup,Name";
                $result = sqlsrv_query($conn, $query) or die("Couldn't execut query");


                while ($data = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){


                $MSGroup = $data['MSGroup'];
                $NAME = $data['Name'];
                $Phone = $data['Phone'];
                $Email = $data['Email'];
                $Image = $data['Image'];
                if ($MSGroup == 'HOD'){
                ?>
                <div>
                    <h1>HOD</h1>

                </div>


                <ol>
                    <?php

                    } else if ($MSGroup == 'Managerial') {
                        ?>
                        <li>
                            <div>
                                <h2>Managerial</h2>
                            </div>
                        </li>
                        <?php
                    }
                    ?>
                </ol>
                <ol>

                    <li>
                        <div><h2>LN</h2></div>

                        <ol>
                            <li>
                                <?php else if ($MSGroup=='LN'){ ?>
                                <div><h2><?php echo "$Name"; ?></h2></div>
                            </li>
                        </ol>
                        <?php
                        }
                        }
                        ?>
                    </li>
                    <li>
                        <div><h2>Lotus Note</h2></div>
                    </li>
                    <li>
                        <div><h2>Hardware</h2></div>
                    </li>
                    <li>
                        <div><h2>Subsystem</h2></div>
                    </li>
                </ol>
                
            </li>
        </ol>
        </li>
        </ol>
    </div>
</div>
<script>
    (function (i, s, o, g, r, a, m) {
        i['GoogleAnalyticsObject'] = r;
        i[r] = i[r] || function () {
            (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date();
        a = s.createElement(o),
            m = s.getElementsByTagName(o)[0];
        a.async = 1;
        a.src = g;
        m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

    ga('create', 'UA-46156385-1', 'cssscript.com');
    ga('send', 'pageview');

</script>
</body>
</html>

Please help me recheck on this error

meewog
  • 1,690
  • 1
  • 22
  • 26
tiqa
  • 57
  • 9
  • Check where you closed the block of the previous `else if ($MSGroup=='Managerial')`. That happens somewhere in between the two, and then you have arbitrary HTML code before the next else. The else has to immediately follow the if block, you can not insert other arbitrary content between the two at will. – CBroe Jul 20 '20 at 08:24
  • @CBroe I already checked the closing brackets and that's the way i want the
  • to loop. Do you have other solutions to allow that to happen?
  • – tiqa Jul 20 '20 at 08:34
  • There's stuff happening between the closing bracket at line line 86, and the next if statement. What did you expect PHP to do with all that HTML? – Ben Hillier Jul 20 '20 at 08:38