Jump to content

Pagination


aaryan2290

Recommended Posts

2nd page in pagination doesnt show any results ,first page is working fine ,please help me

my code is as follows

 

 

 

 

 

 

$sql="SELECT  ID, FirstName, LastName FROM Contacts  WHERE FirstName LIKE '%" . $name .  "%' OR LastName LIKE '%" . $name ."%'"  ;
      
        
      //-run  the query against the mysql query function
      
              
      //-display the result of the array


      $total_records = mysql_num_rows(mysql_query($sql));

      
    
           
    
    

   $sql .= " LIMIT $start, " . NUMBER_PER_PAGE;
     $loop = mysql_query($sql)
    or die ('cannot run the query because: ' . mysql_error());

while ($record = mysql_fetch_assoc($loop))

$result=mysql_query($sql);
      //-create  while loop and loop through result set
      while($row=mysql_fetch_array($result)){
              $FirstName  =$row['FirstName'];
              $LastName=$row['LastName'];
              $ID=$row['ID'];

   
 echo "<li><h1>" . "<a  href=\"search.php?id=$ID\">"   .$FirstName . " </h1></a><a> " . $LastName .  "</a></li>\n";
 echo "</ul>";
 }
echo "<center>" . number_format($total_records) . " search results found</center>";

pagination($page, $total_records, "Firstname=$nameORLastName=$name");

 

 

 

 

 

Link to comment
Share on other sites

$sql .= " LIMIT $start, " . NUMBER_PER_PAGE;

Where does $start come from and what does it contain? Where does NUMBER_PER_PAGE come from and what does it contain?

 

The first option for LIMIT is the where to offset the results, the second is the limit of how many to return.

Edited by iarp
Link to comment
Share on other sites

You're closer than you think, but there is still some work to do.

 

1) mysql_ extension is officially deprecated and actually even removed from php 7. Switch to PDO or at the very least mysqli.

2) typically you want to pass a GET parameter of 'page' or something to that effect so you can set your $start with $_GET['page'] * $_GET['per_page']

 

***edit*** removed quote that I didn't even reference

Edited by seandisanti
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.