Vertaxe Posted January 6, 2010 Share Posted January 6, 2010 Hi guys, I have a search bar which looks at 3 mysql fields and returns results if there are any matches, and it seems to work, however my pagination is messing around, I can't quite work out why. It thinks there are thousands of rows, when there should only be a few... ! Here is a snippet from my pagination_process.php which is where I think the problem lies. $result = mysql_query(" SELECT * FROM table WHERE field1 LIKE \"%$search%\" OR field2 LIKE \"%$search%\" OR field3 LIKE \"%$search%\" "); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $rows_per_page = 4; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } if ($pageno < 1) { $pageno = 1; } $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; Any help is muchly apreciated Quote Link to comment https://forums.phpfreaks.com/topic/187409-result-returning-too-many-rows-for-pagination/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2010 Share Posted January 6, 2010 $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; Those two lines of code fetch the first row form the result set and assign the value from the first column in your table to $numrows. Perhaps you intended to use mysql_num_rows ? Quote Link to comment https://forums.phpfreaks.com/topic/187409-result-returning-too-many-rows-for-pagination/#findComment-989657 Share on other sites More sharing options...
Vertaxe Posted January 6, 2010 Author Share Posted January 6, 2010 Ahah I know what I did wrong, I forgot to use count(*) ! Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/187409-result-returning-too-many-rows-for-pagination/#findComment-989684 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.