aaryan2290 Posted October 6, 2015 Share Posted October 6, 2015 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"); Quote Link to comment https://forums.phpfreaks.com/topic/298457-pagination/ Share on other sites More sharing options...
iarp Posted October 6, 2015 Share Posted October 6, 2015 (edited) $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 October 6, 2015 by iarp Quote Link to comment https://forums.phpfreaks.com/topic/298457-pagination/#findComment-1522476 Share on other sites More sharing options...
seandisanti Posted October 6, 2015 Share Posted October 6, 2015 (edited) 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 October 6, 2015 by seandisanti Quote Link to comment https://forums.phpfreaks.com/topic/298457-pagination/#findComment-1522498 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.