2013-10-20 2 views
0

사용자가 드롭 다운 목록에서 선택할 수있는 카테고리를 기반으로 검색 할 수있는 검색 페이지가 있습니다. 카테고리를 선택하면 데이터와 다음 페이지가 표시되지만 다음을 클릭하면 결과가 표시되지 않습니다. 도와주세요다음에 클릭 할 때 상태에 기반한 페이지 매김이 작동하지 않음

<?php 
include("scripts/connection.php"); 
session_start(); 

if (empty($_SESSION["username"])) { 
    header("Location:login.php"); 
} 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <title>Search Posts</title> 
     <link rel="stylesheet" href="style.css" type="text/css" media="all" /> 
    </head> 
    <body> 
     <div class="main-menu"> 
      <ul id="menu"> 
       <li><a href="mainhome.php">Home</a></li> 
       <li><a href="itempost.php">New Post</a></li> 
       <li><a href="yourpost.php">Your Posts</a></li> 
       <li id="active"><a href="Search.php">Search Posts</a></li> 
       <li class="log"><a href="scripts/logout.php">Log Out</a></li> 
       <li class="log"><a href="account.php">Account</a></li> 
      </ul> 
     </div> 
     <div id="header"><img src="Images/header.gif"/></div> 
     <div id="sidebar"><h2><u>Posts</u></h2><p/> 
      <form method="POST" name="SearchForm" action="search.php"> 
       <table id="mainhomeform"> 
        <tr> 
         <td>Select a category to search through:<p/> 
         <select name="SearchCategory" class="searchlist" tabindex="1"> 
          <option value="<?php if(isset($searchcategory)){echo $searchcategory;}else{echo "Uncategorized";}?>"><?php if(isset($searchcategory)){echo $searchcategory;}else{echo "Uncategorized";}?></option> 
          <option value="Clothing">Clothing</option> 
          <option value="Electronics">Electronics</option> 
          <option value="Furniture">Furniture</option> 
          <option value="Stationary">Stationary</option> 
         </select> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <input name="search" type="submit" class="wbutton" tabindex="3" value="Search" /> 
        </td> 
       </tr> 
       </table> 
      </form> 
     </div> 
     <div id="content"><h2><img src="Images/posts.gif"/></h2> 
      <?php 
      if(isset($_POST['search'])) { 
       $searchcategory = $_POST['SearchCategory']; 
       $searchbutton = $_POST['search']; 

       $search = "SELECT * FROM items WHERE Category='$searchcategory' ORDER BY PostDate DESC"; 
       $select = mysql_query($search); 

       $nr = mysql_num_rows($select); 

       if ($nr>0) { 
        if (isset($_GET['pn'])) { 
         $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); 
        } else { 
         $pn = 1; 
        } 

        $itemsPerPage = 5; 
        $lastPage = ceil($nr/$itemsPerPage); 

        if ($pn < 1) { 
         $pn = 1; 
        } else if ($pn > $lastPage) { 
         $pn = $lastPage; 
        } 

        $centerPages = ""; 

        $sub1 = $pn - 1; 
        $sub2 = $pn - 2; 
        $add1 = $pn + 1; 
        $add2 = $pn + 2; 

        if ($pn == 1) { 
         $centerPages .= '&nbsp; <span class="pagenumbers">' . $pn . '</span> &nbsp;'; 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;'; 

        } else if ($pn == $lastPage) { 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;'; 
         $centerPages .= '&nbsp; <span class="pagenumbers">' . $pn . '</span> &nbsp;'; 

        } else if ($pn > 2 && $pn < ($lastPage - 1)) { 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;'; 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;'; 

         $centerPages .= '&nbsp; <span class="pagenumbers">' . $pn . '</span> &nbsp;'; 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;'; 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;'; 

        } else if ($pn > 1 && $pn < $lastPage) { 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;'; 
         $centerPages .= '&nbsp; <span class="pagenumbers">' . $pn . '</span> &nbsp;'; 
         $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;'; 
        } 

        $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; 
        $select2 = mysql_query("SELECT * FROM items WHERE Category='$searchcategory' ORDER BY PostDate DESC $limit"); 

        $select2_array = array(); 

        $paginationDisplay = ""; 

        if ($lastPage != "1") { 
         if ($pn != 1) { 
          $previous = $pn - 1; 
          $paginationDisplay .= '&nbsp; <a class="button" href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; 
         } 

         $paginationDisplay .= '<span class="pagenumbers">' . $centerPages . '</span>'; 

         if ($pn != $lastPage) { 
          $nextPage = $pn + 1; 
          $paginationDisplay .= '&nbsp; <a class="button" href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; 
         } 
        } 

        for ($count=0; $row = mysql_fetch_array($select2);$count++) { 
         $select2_array[$count] = $row; 

         echo "<table id='home'>"; 

         foreach($select2_array as $itemshome); 

         echo "<tr>"; 
         echo "<td class='title'>". $itemshome ['Title']."</td>"; 
         echo "<td class='rf'>". $itemshome ['PostDate']."<br/>".$itemshome ['Category']."</td>"; 
         echo "<hr>"; 
         echo "</tr>"; 
         echo "<tr>"; 
         echo "<td colspan='3'>"."<img src='$itemshome[Image1]' class='pic' alt='userimage' />"; 
         echo "<img src='$itemshome[Image2]' class='pic' alt='userimage' />"; 
         echo "<img src='$itemshome[Image3]' class='pic' alt='userimage' />"."</td>"; 
         echo "</tr>"; 
         echo "<tr>"; 
         echo "<td colspan='3'>"."<textarea name='Description' type='text' class='description' tabindex='2' readonly >".$itemshome ['Description']."</textarea>"."</td>"; 
         echo "</tr>"; 
         echo "</tr>"; 
        } 

        echo "</table>"; 
        echo "$paginationDisplay"; 

       } else { 
        $empty = '<div class="error">That category is empty.</div>'; 

        echo $empty; 
       } 
      } 
      ?> 

      <div class="footer"> 
       <hr/> 
       Copyright &copy;<br/>Designed Using XHTML 1.1 
       <p id="rf">Designed by Mutondo Sitemba</p> 
      </div> 
     </div> 
    </body> 
</html> 

답변

0

귀하의 링크는 pn이지만 searchCategory는 없습니다. 그래서 당신의 쿼리는 다음과 같습니다 : SELECT * FROM items 카테고리 = ''ORDER BY PostDate DESC

빈 결과에 문제가있는 경우, 첫 번째 단계로서 쿼리를 인쇄하고 올바르게 작성되었는지 확인해야합니다. 일반적으로 이것은 도움이됩니다.

+0

감사합니다. 문제가 있다고 생각합니다. 어떻게 포함시켜야합니까? SELECT * FROM items where Category = 'Clothing'ORDER BY PostDate DESC –

+0

의류 카테고리를 선택한 후 두 번째 쿼리를 표시하면 다음과 같이 표시됩니다. Resource id # 6 –

0

isset ($ _ POST [ '검색'])에 대한 점검에 문제가있을 수 있습니까? 다음을 클릭하면 양식의 게시판이 없습니다.

+0

감사합니다. 당신의 응답 그러나 나는 그것을 제거하는 것을 시도하고 나는 아직도 동일한 문제를 얻었다 –

관련 문제