【问题标题】:PHP: Displaying blog pages in unique page [closed]PHP:在唯一页面中显示博客页面[关闭]
【发布时间】:2013-06-12 20:01:27
【问题描述】:

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

解析错误:语法错误,第 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;
      }
?>

【问题讨论】:

  • 我已经给你一点你的问题,以免你的个人资料被删除,但是你必须注意你的代码编写,因为它是无序的,可能使用 python一小段时间(1 天)你可以写更多的 orderer 代码并且没有这种问题

标签: php mysql database unique blogs


【解决方案1】:

试试这个...

只需复制粘贴即可运行...

<?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;}
  }}

  ;?>

【讨论】:

    【解决方案2】:

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

    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;
      }
    

    【讨论】:

    • 给出了错误错误:语法错误,意外'{',期待':'
    • 我修改了我的答案。在我提交之后,我注意到你已经去掉了一堆花括号。
    • 如果您懒得阅读,请使用 KyleK 的答案。
    猜你喜欢
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多