嵌套if else语法错误php

时间:2017-08-15 13:55:35

标签: php

   it says syntax error t_else, what could be the problem? 

这真的让我疯狂地找到我在这段代码中做错了什么 什么可能是我的错误?

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

这里是完整的代码,错误给了我什么,请帮助我们,我需要花很多时间才能解决这类问题我已经尝试了一切,但也许你们可以解决我的问题hahahaha它真的耗尽了我的思绪在这里,我已经对我目前面临的问题感到头脑清醒

2 个答案:

答案 0 :(得分:-1)

你缺少&lt;在第一个while循环内的一个标签处(当我复制/粘贴你的代码时,正好在第21行)。这可能是它无法识别else语句的原因,因为它无法正确使用它。

答案 1 :(得分:-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...
                          }
                     }                           
                      ?>