2017-08-15 70 views
0
it says syntax error t_else, what could be the problem? 

它真的让我疯狂找到我在这段代码中做错了什么 什么可能是我的错误在这里?嵌套如果其他语法错误php

<?php 
include("../mysql_connect.php"); 
if (isset($_POST['search_form'])) { 
    $page1 = $_GET['page']; 
    if ($page1 == "" || $page1 == 1) { 
     $page1 = 0; 
    } 
    else { 
     $page1 = ($page1 * 5) - 5; 
    } 
    $query = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' "; 
    $result = mysql_query($query); 
    while ($row = mysql_fetch_array($result)) { 
     ?> 
     <table class="table table-hover" border="2"> 
      <col width="50%"></col> 
      <col width="40%"></col> 
      <col width="20%"></col> 
      <tr> 
       <td rowspan="3"> 
        a href="news_view.php?id=<?php echo $row['news_id']; ?>"> 
        <img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300" width="500"> 
        </a> 
       </td> 
       <td>Title: <?php echo $row['news_title']; ?></td> 

      </tr> 
      <tr> 
       <td>Author: <?php echo $row['news_author']; ?></td> 
      </tr> 

      <tr> 
       <td>Date: <?php echo $row['news_date_filed']; ?></td> 
      </tr> 
      </thead> 
     </table> 
     <?php 
    } 
    $query1 = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'"; 
    $result1 = mysql_query($query1); 
    $row1 = mysql_num_rows($result1); 
    $pagecount = $row1/5; 
    $pagecount = ceil($pagecount); 

    for ($count = 1; $count <= $pagecount; $count++) { 
     ?> 

     <a href="news.php?page=<?php echo $count; ?>"><?php echo $count ?></a> 

     <?php 
    } 
} 
else{ 
    $page1 = $_GET['page']; 
    if ($page1 == "" || $page1 == 1) { 
     $page1 = 0; 
    } 
    else { 
     $page1 = ($page1 * 5) - 5; 
    } 
    $query = "select * from tbl_news where news_status='Active' limit $page1,5"; 
    $result = mysql_query($query); 
    while ($row = mysql_fetch_array($result)) { 
     ?> 
     <table class="table table-hover" border="2"> 
      <col width="50%"></col> 
      <col width="40%"></col> 
      <col width="20%"></col> 
      <tr> 
       <td rowspan="3"> 
        <a href="news_view.php?id=<?php echo $row['news_id']; ?>"> 
         <img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300" 
          width="500"> 
        </a> 
       </td> 
       <td>Title: <?php echo $row['news_title']; ?></td> 

      </tr> 
      <tr> 
       <td>Author: <?php echo $row['news_author']; ?></td> 
      </tr> 

      <tr> 
       <td>Date: <?php echo $row['news_date_filed']; ?></td> 
      </tr> 
      </thead> 
     </table> 
     <?php 
    } 
    ?> 
    <?php 
    $query1 = "select * from tbl_news where news_status='Active'"; 
    $result1 = mysql_query($query1); 
    $row1 = mysql_num_rows($result1); 
    $pagecount = $row1/5; 
    $pagecount = ceil($pagecount); 

    for ($count = 1; $count <= $pagecount; $count++) { 
     ?> 

     <a href="news.php?page=<?php echo $count; ?>"><?php echo $count ?></a> 

     <?php # code... 
    } 
} 
?> 

这里是完整的代码,什么errror给我,请帮我人需要我一大把的有这样那样的问题,我已经尝试了所有我能时间,但也许你们可以我解决我的问题hahahaha它在这里真的让我心动不已,我已经对我目前面临的问题非常头疼

+1

mysql_ *函数自PHP 5.5.0起弃用,自PHP 7.0.0起删除。切换您的代码以使用[PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php)或[mysqli](http://php.net/manual/en/mysqli。改为quickstart.prepared-statements.php)。 – aynber

+1

取出你的关闭if括号和else语句之间的'?><?php'。当你打破这样的控制时,PHP不喜欢它。 – aynber

+0

难怪有一个错误。我永远无法跟踪所有的开放和关闭标签。你知道这个错误在哪里吗?什么线? – Andreas

回答

-1

您在第一个while循环(当我复制/粘贴代码时,完全在第21行)的a标记中缺少<。这可能是它不能识别else语句的原因,因为它不能正确地得到它。

+0

它仍然是一个错误 – tenteren

+0

你不应该回答重复的问题。 – GrumpyCrouton

-1

试试这段代码。可能会解决你的问题。 我更正了你的代码中的一些语法错误。

<?php 
        include("../mysql_connect.php"); 
        if (isset($_POST['search_form'])) { 
         $page1=$_GET['page']; 
         if ($page1=="" || $page1==1) { 
          $page1=0; 
         } 
         else{ 
          $page1=($page1*5)-5; 
         } 
         $query="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' "; 
         $result=mysql_query($query); 
         while ($row=mysql_fetch_array($result)) { 
        ?> 
          <table class="table table-hover" border="2"> 
            <col width="50%"></col> 
            <col width="40%"></col> 
            <col width="20%"></col> 
           <tr> 
           <td rowspan="3"> 
            <a href="news_view.php?id=<?php echo $row['news_id'];?>"> 
             <img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500"> 
            </a> 
           </td> 
            <td>Title: <?php echo $row['news_title'];?></td> 

           </tr> 
           <tr> 
            <td>Author: <?php echo $row['news_author'];?></td> 
           </tr> 

           <tr> 
            <td>Date: <?php echo $row['news_date_filed'];?></td> 
          </tr> 
           </thead> 
         </table>  
        <?php 
         } 
         $query1="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'"; 
         $result1=mysql_query($query1); 
         $row1=mysql_num_rows($result1); 
         $pagecount=$row1/5; 
         $pagecount=ceil($pagecount); 

         for ($count=1; $count <= $pagecount ; $count++) { 


    ?> 

            <a href="news.php?page=<?php echo $count;?>"><?php echo $count?></a> 

       <?php 
         } 
        }else{ 
          $page1=$_GET['page']; 
          if ($page1=="" || $page1==1) { 
           $page1=0; 
          } 
          else{ 
           $page1=($page1*5)-5; 
          } 
          $query="select * from tbl_news where news_status='Active' limit $page1,5"; 
          $result=mysql_query($query); 
          while ($row=mysql_fetch_array($result)) { 
              ?> 
         <table class="table table-hover" border="2"> 
             <col width="50%"></col> 
             <col width="40%"></col> 
             <col width="20%"></col> 
            <tr> 
            <td rowspan="3"> 
             <a href="news_view.php?id=<?php echo $row['news_id'];?>"> 
              <img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500"> 
             </a> 
            </td> 
             <td>Title: <?php echo $row['news_title'];?></td> 

            </tr> 
            <tr> 
             <td>Author: <?php echo $row['news_author'];?></td> 
            </tr> 

            <tr> 
             <td>Date: <?php echo $row['news_date_filed'];?></td> 
           </tr> 
            </thead> 
          </table>  
         <?php 
          } 
          $query1="select * from tbl_news where news_status='Active'"; 
          $result1=mysql_query($query1); 
          $row1=mysql_num_rows($result1); 
          $pagecount=$row1/5; 
          $pagecount=ceil($pagecount); 

          for ($count=1; $count <= $pagecount ; $count++) { 
         ?> 

             <a href="news.php?page=<?php echo $count;?>"><?php echo $count?></a> 

         <?php  # code... 
          } 
        }       
         ?> 
+0

这样做**不**以有用的方式回答问题_。 **为什么**你相信这是答案吗? **它是如何工作的?仅仅告诉某人在没有任何语境或意义的情况下改变他们的代码并不能帮助他们了解他们做错了什么,对未来的读者也没有多大用处。 – GrumpyCrouton

+0

**请**,不要使用'mysql_ *'函数获取新代码。他们不再被维护,社区已经开始[弃用过程](http://news.php.net/php.internals/53799),并且'mysql_ *'函数已经在PHP 7中被正式删除。相反,你应该了解[已准备好的语句](https://en.wikipedia.org/wiki/Prepared_statement)并使用“PDO”或“mysqli_ *”。如果你不能决定,[这篇文章将有助于选择你最好的选择](http://php.net/manual/en/mysqlinfo.api.choosing.php)。 – GrumpyCrouton

+0

[Little Bobby](http://bobby-tables.com/)表示** [您有SQL注入攻击风险](https://stackoverflow.com/q/60174/)**。了解[MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)的[Prepared Statements](准备语句)(https://en.wikipedia.org/wiki/Prepared_statement)。即使** [转义字符串](https://stackoverflow.com/q/5741187)**是不安全的!我推荐'PDO',我[写了一个函数](https://stackoverflow.com/a/45514591)使它非常容易**,非常干净**,并且更加安全** **比使用非参数化查询。 – GrumpyCrouton