Mavent Posted December 30, 2011 Share Posted December 30, 2011 Hello everyone; I have a database with about ten thousand entries. Obviously, I'd like to paginate it. I did what I normally do in these situations: I went to Google, and started looking for sample code as a place to start. The problem is that every single sample I could find was apparently written in 1605 by Tibetan Monks or something, because absolutely none of it works. By "doesn't work" I mean "constantly throws errors denying that my Server has ever heard of the syntax being used." Now, I know the DB is set up correctly in all other respects, because I'm able to Query it for all my other processes. I can add to it, display it, edit it, and so forth, so I know it's not a basic connection problem. The errors center around counting the number of rows in the table. I'm five examples in, and so far three of them have told me that "$rows = mysql_num_rows($data)" isn't a real thing, and the other two told me that COUNT(*) "doesn't contain any data". Given that I'm clearly new at this, I'd tend to blame myself, except that I'm not writing a single line of the code. All I'm doing is using the sample code and putting in my connection/database information, using the identical connection info that I'm using to create and display the database in the first place. Soooooo.... my question is this: can anyone steer me towards a current, working sample of pagination code? I'd be forever in your debt. Thanks! Oh, here's the code that's currently failing: $sql = "SELECT COUNT(*) FROM mytable"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; The error is: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource Kyle Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/ Share on other sites More sharing options...
abrahamgarcia27 Posted December 30, 2011 Share Posted December 30, 2011 try this phpsense onpagination class http://phpsense.com/2007/php-pagination-script/ or this forum has a basic pagination script tutorial http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1302700 Share on other sites More sharing options...
Pikachu2000 Posted December 30, 2011 Share Posted December 30, 2011 From your error message, the connection is not established/failed. Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1302701 Share on other sites More sharing options...
Mavent Posted December 30, 2011 Author Share Posted December 30, 2011 try this phpsense onpagination class http://phpsense.com/2007/php-pagination-script/ Thank you very much for the links- I got this one up and running in about 30 seconds. At the risk of sounding stupid though, shouldn't it be displaying some actual content along with the links? Here's the result: http://www.secretauctions.com/pagination/usage.php You'll note that it's indeed giving me the pagination... but no content. Here's what the unpaginated page looks like, just to establish that there is, in fact, content in the database: http://www.secretauctions.com/carlist.php Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1302709 Share on other sites More sharing options...
Mavent Posted December 30, 2011 Author Share Posted December 30, 2011 From your error message, the connection is not established/failed. Yeah, that's what it looked like to me, too, but the connection code is exactly the same as what I'm using on this page: http://www.secretauctions.com/carlist.php That page is obviously connecting, which makes the failure of the other code just that much more frustrating. Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1302710 Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2011 Share Posted December 31, 2011 shouldn't it be displaying some actual content Only if you modified the display code to be specific to your table column(s.) Do you have php's error_reporting set to E_ALL so that all the php detected errors will be reported? Beyond that, you would need to post your usage.php code that you modified to use with your database table. Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1302725 Share on other sites More sharing options...
Mavent Posted December 31, 2011 Author Share Posted December 31, 2011 shouldn't it be displaying some actual content Only if you modified the display code to be specific to your table column(s.) That was it. I failed to notice where I needed to do the column names the first time through. Now everything is nearly perfect: http://www.secretauctions.com/carlist1.php?page=2&v1=Name&v2=ASC I say "nearly" because the Pagination appears to believe that B comes before A in the Alphabet, but for the most part it's great. I'm going to assume for the moment that the minor problems are due to mistakes that I'll be able to find once it's no longer 2 o'clock in the morning. Thanks to everyone! Kyle Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1302791 Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2011 Share Posted December 31, 2011 The reason you have a little more than 1 page of data that is out of alphabetically order and comes before the rest is because that data has some white-space characters (looks some with 1 and some with 2 space characters in the 'view source') at the start of each value and the ORDER BY places those rows first. You need to trim the data, at least in the name column, in your database table, so that the ORDER BY will produce the correct results. Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1302817 Share on other sites More sharing options...
Mavent Posted January 1, 2012 Author Share Posted January 1, 2012 The reason you have a little more than 1 page of data that is out of alphabetically order and comes before the rest is because that data has some white-space characters (looks some with 1 and some with 2 space characters in the 'view source') at the start of each value and the ORDER BY places those rows first. You need to trim the data, at least in the name column, in your database table, so that the ORDER BY will produce the correct results. You are again correct. Thanks! Sorry about all the newbie mistakes- this is my first database project. Quote Link to comment https://forums.phpfreaks.com/topic/254099-i-need-a-good-example-of-paginating-database-results/#findComment-1303150 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.