0

谁能告诉我为什么我的代码会出现这个错误:

解析错误:语法错误,第 30 行 C:\wamp\www\blogsite\display.php 中的意外 '}'

第 30 行是最后一个 {

一切看起来都不错,但我想我错过了一些东西

<<?php

if(isset($_GET['id']) && is_int($_GET['id'])) {
    $blogId = (int)$_GET['id'];
    $query = "SELECT blog_id, title, date, body FROM content WHERE blog_id='$blogId'";
    // run query and get record data and output it

} else {
    //code to return all records as list
    $dbinfo = "SELECT blog_id, title, date, body FROM content ORDER BY blog_id DESC LIMIT 0, 3";
    $result = mysql_query($dbinfo) or die(mysql_error());
    $return = '<p><a href="index.php"> Go Back To Content Page</a></p>';


   if(mysql_num_rows($result) !=0):
   while($row = mysql_fetch_assoc($result)){
   echo '<div id="roundedbox"><h2><a href="index.php?id=' . $row['blog_id'].$row['title'] . ' </a></h2>';
   echo '<div id="date"><h5><p>' . $row['date'] . '</p></h5></div>';
   echo substr('<p>' . $row['body'] . '</p>',0, 90)." .... "." read more</div>";

       }
       else:
         echo '<p> UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST </p>'; 
         echo $return;
      }
?>
4

2 回答 2

2

尝试这个...

只需复制和粘贴,它应该运行...

<?php

if(isset($_GET['id']) && is_int($_GET['id'])) {
$blogId = (int)$_GET['id'];
$query = "SELECT blog_id, title, date, body FROM content WHERE blog_id='$blogId'";
// run query and get record data and output it

 } else {
//code to return all records as list
$dbinfo = "SELECT blog_id, title, date, body FROM content ORDER BY blog_id DESC LIMIT 0, 3";
$result = mysql_query($dbinfo) or die(mysql_error());
$return = '<p><a href="index.php"> Go Back To Content Page</a></p>';


 if(mysql_num_rows($result) !=0){
 while($row = mysql_fetch_assoc($result)){
 echo '<div id="roundedbox"><h2><a href="index.php?id=' . $row['blog_id'].$row['title'] . ' </a></h2>';
 echo '<div id="date"><h5><p>' . $row['date'] . '</p></h5></div>';
 echo substr('<p>' . $row['body'] . '</p>',0, 90)." .... "." read more</div>";

   }} else{
     echo '<p> UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST </p>'; 
     echo $return;}
  }}

  ;?>
于 2013-06-12T20:07:18.793 回答
0

您需要在这里使用花括号而不是冒号。

if(mysql_num_rows($result) !=0):

您还需要在上面的下一个 if 语句之前关闭第一个 else 上的花括号。

最后一个 else 也应该使用花括号而不是冒号。

else {
     echo '<p> UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST </p>'; 
     echo $return;
  }
于 2013-06-12T20:03:54.033 回答