johnsmith153 Posted January 19, 2011 Share Posted January 19, 2011 I want a simple function that converts a sql query into two queries for pagination purposes. So if the sql query is "SELECT `Name` FROM table1" I would like to perform: "SELECT COUNT(*) FROM table 1" and "SELECT `Name` FROM table1 LIMIT 10, 20" (example) (1) Would this work for most basic queries? (obviously if LIMIT wasn't already used)? (2) What command would I use to convert "SELECT `Name` FROM table1" to "SELECT COUNT(*) FROM table 1" I am aware there is more involved than this, but am just interested in the query side of things. Link to comment https://forums.phpfreaks.com/topic/224983-function-to-convert-sql-query-for-pagination/ Share on other sites More sharing options...
webbhelp Posted January 19, 2011 Share Posted January 19, 2011 Use a variable: $type = 'name'; "SELECT $type FROM table1" Or $type = 'COUNT(*)'; "SELECT $type FROM table1" then yo u can decide what with an if() if(...) { $type = 'name'; } else { $type = 'COUNT(*)'; } Hope this help Link to comment https://forums.phpfreaks.com/topic/224983-function-to-convert-sql-query-for-pagination/#findComment-1162051 Share on other sites More sharing options...
QuickOldCar Posted January 19, 2011 Share Posted January 19, 2011 Although there are a few, very few pagination scripts out there, they are very limited in what can do because all databases and circumstances are different, so I really doubt would ever see a simple function for this. It takes manual work for your specific needs to make it all work together. What webbhelp said is correct. You can do it by switch/case or if/else statements and use variables to reflect any superglobals like GET,POST,RESQUEST and so on. I did a few examples on other posts can check out Here's a post in the forum for a pagination that controls the count for start rows http://www.phpfreaks.com/forums/php-coding-help/results-on-multiple-pages-help/msg1506457/#msg1506457 Live Demo for the above code http://get.blogdns.com/dynaindex/paginate.php Otherwise I do have an example of code involving multi-select queries based on search terms, it won't be a working example but can get an idea how to go about it. http://www.phpfreaks.com/forums/php-coding-help/remove-commas-from-search-string-and-pass-results-to-a-query/msg1504627/#msg1504627 Link to comment https://forums.phpfreaks.com/topic/224983-function-to-convert-sql-query-for-pagination/#findComment-1162077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.