2010-05-03 71 views
0

我已经实现this pagination class for search.php页面在一个单独的文件中称为class.pagination.php,但是当我执行搜索页面时,什么也没有发生。它只是显示一个空白页面。分页在PHP错误

这是我的search.php文件,在那里我调用这个类:

<?php 


    include 'config.php'; 
    require ('class.pagination.php'); 


    $search_result = ""; 

    $search_result = $_GET["q"]; 
    $search_result = trim($search_result); 

    //Check if the string is empty 
    if ($search_result == "") { 
     echo "<p class='error'>Search Error. Please Enter Your Search Query.</p>" ; 
     exit(); 
      } 


    //search query for multiple keywords 
    if(!empty($search_result)) 
    { 
     // the table to search 
     $table = "thquotes"; 
     // explode search words into an array 
     $arraySearch = explode(" ", $search_result); 
     // table fields to search 
     $arrayFields = array(0 => "cQuotes"); 
     $countSearch = count($arraySearch); 
     $a = 0; 
     $b = 0; 
     $query = "SELECT cQuotes, vAuthor, cArabic, vReference FROM ".$table." WHERE ("; 
     $countFields = count($arrayFields); 
     while ($a < $countFields) 
     { 
     while ($b < $countSearch) 
     { 
      $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'"; 
      $b++; 
      if ($b < $countSearch) 
      { 
      $query = $query." AND "; 
      } 
     } 
     $b = 0; 
     $a++; 
     if ($a < $countFields) 
     { 
      $query = $query.") OR ("; 
     } 
     } 
     $query = $query.")"; 
     $result = mysql_query($query, $conn) 
     or die ('Error: '.mysql_error()); 

     $totalrows = mysql_num_rows($result); 

     if($totalrows < 1) 
     { 
     echo '<span class="error2">No matches found for "'.$search_result.'"</span>'; 
     } 
     else 
     { 

    ?> 

    <div class="caption">Search Results</div> 
    <div class="center_div"> 
    <table> 
     <?php while ($row= mysql_fetch_array($result, MYSQL_ASSOC)) { 
      $cQuote = highlightWords(htmlspecialchars($row['cQuotes']), $search_result); 
      ?> 
      <tr> 
      <td style="text-align:right; font-size:15px;"><?php h($row['cArabic']); ?></td> 
       <td style="font-size:16px;"><?php echo $cQuote; ?></td> 
       <td style="font-size:12px;"><?php h($row['vAuthor']); ?></td> 
       <td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']); ?></td> 
      </tr> 
     <?php } ?> 
    </table> 
    </div> 

    <?php 
    } 
    } 
    else { 
     exit(); 
    } 

    //Setting Pagination 
    $pagination = new pagination(); 
    $pagination->byPage = 5; 
    $pagination->rows = $totalrows; // number of records in a table-back mysql_num_rows() instance or another, you have to play 
    $from = $pagination->fromPagination(); // sql used for applications such LIMIT $ from, $ pagination-> byPage 
    $pages = $pagination->pages(); 

    if(isset($pages)) {?> 
    <div class="pagination"> 
     <?foreach ($pages as $key){?> 
     <?if($key['current'] == 1) {?> 
     <a href="?p=<?=$key['p']?>" class="active"><?=$key['page']?></a> 
     <?} else {?> 
     <a href="?p=<?=$key['p']?>" class="inactive"><?=$key['page']?></a> 
     <?}?> 
     <?}?> 
    </div> 
    <?} 
    //End Pagination 
    ?> 
+0

空白页?你的服务器是否有错误被抑制?可能有语法错误。 – 2010-05-03 20:03:40

+0

我将此代码添加到我的php页面ini_set('display_errors',1); error_reporting(E_ALL | E_STRICT);'。 。它不显示任何错误。 – input 2010-05-03 20:17:30

回答

0

尝试echo之前的东西包括。

+0

我做到了。奇怪的是,它不会回显没有显示任何内容的文字。看起来好像search.php文件没有被读取。但如果我从文件中删除分页包含和它的代码,它会顺利地显示搜索结果 - 没有分页,当然!有什么可能是错的? – input 2010-05-04 08:42:16

+0

如果删除'require('class.pagination.php');'使问题消失,当然问题与该文件有关。 – 2010-05-04 09:14:06

1

在您需要class.pagination.php开始,但你的博客,它说的文件名是pagination.class.php。这是问题吗?

+0

我重命名了该文件。这不是问题。 那不是我的博客。 – input 2010-05-04 08:40:47