Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    87
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Angry Pagination for search results not working

    The PHP code below is displaying only the first page of searched items. What is making the other pages of the searched item blank? Please help.
    Code:
    <?php
    
    $page = (int) $_GET['page'];
    if ($page < 1) $page = 1;
    
             // Include database connection settings
              include('config.inc'); 
    
             //-select the database to use
             $mydb=mysql_select_db("a3763404_posts");
    
    if(isset($_POST['submit']))
    {
    if(isset($_GET['go']))
      {
         if(preg_match("/[A-Z | a-z]+/", $_POST['name']))
    	    {
              $name=$_POST['name'];
    
            //-query the database table
            //$sql="SELECT * FROM entries WHERE Title LIKE '%" . $name . "%' OR Title LIKE '%" . $name . "%' OR Post LIKE '%" . $name ."%' OR Date LIKE '%" . $name ."%'LIMIT $startResults, $resultsPerPage";  
    
            //-run the query against the mysql query function
            $result=mysql_query("SELECT * FROM entries WHERE Title LIKE '%" . $name . "%' OR Post LIKE '%" . $name ."%' OR Date LIKE '%" . $name ."%' LIMIT $startResults, $resultsPerPage");
    
            //-count results
            
    		$numberOfPages = 100;
            $resultsPerPage = 20;
            $startResults = ($page - 1) * $resultsPerPage;
    		$numrows = mysql_num_rows(mysql_query("SELECT * FROM entries WHERE Title LIKE '%" . $name . "%' OR Post LIKE '%" . $name ."%' OR Date LIKE '%" . $name ."%'"));
            $totalPages = ceil($numrows / $resultsPerPage);
    		$result=mysql_query("SELECT * FROM entries WHERE Title LIKE '%" . $name . "%' OR Post LIKE '%" . $name ."%' OR Date LIKE '%" . $name ."%' LIMIT $startResults, $resultsPerPage");
            //$numrows=mysql_num_rows($numrows);  
    
    		
            echo "<p>" .$numrows . " Results found for " . stripslashes($name) . "</p>"; 
    
            
               while ($output = mysql_fetch_array($result))
                 { 
                   echo '<a href="selected_post.php?Index='.$output['Index'].'">' .$output['Title'].'</a><br>'; 
                 }
    
           $halfPages = floor($numberOfPages / 2);
           $range = array('start' => 1, 'end' => $totalPages);
           $isEven = ($numberOfPages % 2 == 0);
           $atRangeEnd = $totalPages - $halfPages;
    
           if($isEven) $atRangeEnd++;
    
           if($totalPages > $numberOfPages)
                {
    	         if($page <= $halfPages)
    		     $range['end'] = $numberOfPages;
    	         elseif ($page >= $atRangeEnd)
    		     $range['start'] = $totalPages - $numberOfPages + 1;
    	         else
    	           {
    		         $range['start'] = $page - $halfPages;
    		         $range['end'] = $page + $halfPages;
    		         if($isEven) $range['end']--;
    	           }
                }
    
            if($page > 1)
    	    echo '<a href="?page='.($page - 1).'">&laquo;</a>&nbsp';
    
            for ($i = $range['start']; $i <= $range['end']; $i++)
              {
    	        if($i == $page)
    		    echo '<strong>'.$i.'</strong>&nbsp;';
    	        else
    		    echo '<a href="?page='.$i.'">'.$i.'</a>&nbsp;';
              }
            if ($page < $totalPages)
    	     echo '<a href="?page='.($page + 1).'">&raquo;</a>&nbsp;';
                          
            }
                     
        else
            {
               echo "<p>Please enter a search query</p>";
            }	
       }
     }
    ?>

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    im not sure, you have a lot of extra bits of code in there

    and probably too many querys too
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    87
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Arcticwarrio, please message an expert to help me. It's giving me stress.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •