0

我是这个编码游戏的新手,但我在这段代码中找不到我的语法/解析错误。错误是说第 86 行是代码的结尾。我试图添加括号,但没有运气。这可能是一个基本问题,但我一直在努力解决它,所以我想我会在这里拍摄它,看看我是否可以获得一些明确的指导并停止只是扔东西。

    <html>
    <head>
<title>View Guestbook</title>
<link rel="stylesheet" type="text/css" href="css/king.css" />
  </head>

   <body>
  <img src="images/KingLogo.jpg"><br>

    <?php
include "king_common_functions.php";

viewGuestbook();

     //****************************************************************
     //Display Admin Guestbook Data (All Submissions)
    //****************************************************************

function viewGuestbook()
{
    $outputDisplay = "";
    $myrowcount = 0;

    $statement  = "SELECT lastname, firstname, contact_type, contact_info,";
    $statement  = "city, comments, date_added";
    $statement .= "FROM u1585_Guestbook ";
    $statement .= "ORDER BY lastname ";

    $sqlResults = selectResults($statement);

    $error_or_rows = $sqlResults[0];

    if (substr($error_or_rows, 0 , 5) == 'ERROR')
    {
        print "<br />Error on DB";
        print $error_or_rows;
    } else {
        $arraySize = $error_or_rows;

            for ($i=1; $i <= $error_or_rows; $i++)
            {
                $lastname = $sqlResults[$i]['lastname'];
                $firstname = $sqlResults[$i]['firstname'];
                $contact_type = $sqlResults[$i]['contact_type'];
                $contact_info = $sqlResults[$i]['contact_info'];
                $city = $sqlResults[$i]['city'];
                $comments = $sqlResults[$i]['comments'];
                $date_added = $sqlResults[$i]['date_added'];

                $outputDisplay  = "<h3>View Guestbook:</h3>";
                $outputDisplay .= '<table border=1 style="color: black;">';
                $outputDisplay .= '<tr><th>Last Name</th><th>First Name</th><th>Contact Type</th><th>Contact Info</th>';
                $outputDisplay .= '<th>City</th><th>Comments</th><th>Date Added</th></tr>';

                $numresults = mysql_num_rows($sqlResults);

                for ($j = 0; $j < $numresults; $j++)
                {
                    if (!($j % 2) == 0)
                    {
                        $outputDisplay .= "<tr style=\"background-color: #F5DEB3;\">";
                    } else {
                        $outputDisplay .= "<tr style=\"background-color: white;\">";
                    }

                $myrowcount++;

                $outputDisplay .= "<td>".$lastname."</td>";
                $outputDisplay .= "<td>".$firstname."</td>";
                $outputDisplay .= "<td>".$contact_type."</td>";
                $outputDisplay .= "<td>".$contact_info."</td>";
                $outputDisplay .= "<td>".$city."</td>";
                $outputDisplay .= "<td>".$comments."</td>";
                $outputDisplay .= "<td>".$date_added."</td>";
                $outputDisplay .= "</tr>";
            }
    }
    $outputDisplay .= "</table>";
    $outputDisplay .= "<br /><br /><b>Number of Rows in Results: $myrowcount </b>    <br /><br />";
    print $outputDisplay;
    }
    ?>
    </p>

     </body>
    </html>
4

2 回答 2

3

我认为您的for循环没有正确关闭:

for ($j = 0; $j < $numresults; $j++)
    {
    if (!($j % 2) == 0)
       {
       $outputDisplay .= "<tr style=\"background-color: #F5DEB3;\">";
    } else {
       $outputDisplay .= "<tr style=\"background-color: white;\">";
    }

$myrowcount++;

缩进代码可以更容易地发现缺少大括号的位置。

于 2012-08-21T20:47:01.133 回答
1

您的函数缺少右括号。一个不错的 IDE 或文本编辑器会很快为您发现这一点。

于 2012-08-21T20:46:02.117 回答