Hyperjase Posted December 29, 2008 Share Posted December 29, 2008 Hey all, been looking round on how to make a MySQL result paginate, I've looked at some examples but am pretty lost ... can anyone help me with paginating this please? <?php $result = mysql_query("SELECT DISTINCT album FROM samdb.songlist WHERE songtype = 'S' GROUP BY album ORDER BY album ASC") or die(mysql_error()); echo "<table align='center' border='0' width='60%'>"; echo "<tr><td class='tblbg'>Complete Album List</td></tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td height='20'>"; echo '<a href="playlist.php?search='.$row['album'].'&dcat=album">'.$row['album'].'</a>'; echo "</td></tr>"; } echo "</table>"; ?> All I really want to do is just have say 20 results per page before rolling over to the next .... I'd be grateful if anyone could show me what I need to do, will be handy for future! Thanks, Jason Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/ Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 Hate to sound like the most unhelpful person on this forum be redirecting you but have you seen the tutorial oh php freaks? Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725484 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Pagination. Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725492 Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 Maq has made it even easier for you Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725503 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 That's why I'm here Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725509 Share on other sites More sharing options...
Noskiw Posted December 29, 2008 Share Posted December 29, 2008 i could give you the code i used for mine, or you could read that tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725557 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 i could give you the code i used for mine That wouldn't be any fun! Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725562 Share on other sites More sharing options...
Hyperjase Posted December 29, 2008 Author Share Posted December 29, 2008 Thanks guys, yeah I've been through that and to be totally honest, it confused the hell outta me, all I need to do is get the total unique albums from the database then format 20 per page. Some of the tutorial seems to cover stuff that isn't applicable to my situation, I'm so-so with PHP, not fantastically well versed, maybe I was being a little lazy posting my code, but I am truly lost!! Thanks Jason Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725602 Share on other sites More sharing options...
MatthewJ Posted December 29, 2008 Share Posted December 29, 2008 That tutorial is a very good one... It took me a few tries to figure it out when I was first learning. I mean, we can't just give you the fish, that would defeat the whole point Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725651 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 maybe I was being a little lazy posting my code, but I am truly lost!! The best thing to do is make an attempt and post a specific problem. This way, it shows that you tried so people will be more willing to help you AND it's easier for us because if there's a specific problem than we can usually answer relatively quickly. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-725657 Share on other sites More sharing options...
Hyperjase Posted December 30, 2008 Author Share Posted December 30, 2008 Ok, I've used existing code elsewhere on the same script to do something similar which is order them alphabetically, however I've stumbled over a few small issues, I have tried to work my way around one in particular but think it needs more code than I'm technically able to do, here's the code I have. <?php $let = $_GET['letter']; $result = mysql_query("SELECT DISTINCT album FROM samdb.songlist WHERE album LIKE '$let%' GROUP BY album ORDER BY album ASC") or die(mysql_error()); echo "<table align='center' border='0' width='60%'>"; echo "<tr><td class='tblbg' colspan='2'>Complete Album List</td></tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr>"; echo "<td height='20'>"; echo '<a href="playlist.php?search='.$row['album'].'&dcat=album">'.$row['album'].'</a>'; echo "</td></tr>"; } // HERE echo "Search by Album:<br /><a href='?letter=0'>0 - 9</a>"; for($c=ord('A');$c<=ord('Z');$c++) { $v = chr($c); echo ", <a href='?letter=$v'>$v</a>"; } // TO HERE echo "</table>"; ?> everything between the // is what I've used, I had to add the $let variable as for whatever reason it wasn't picking it up from $v. The problem I have is that I have albums listed alphanumerically and also odd characters (* being the starting character). How do I alter the ?letter=0 to something that will pick up everything non-alphanumeric? I will experiment but any help in the right direction would be gratefully appreciated. Jason Quote Link to comment https://forums.phpfreaks.com/topic/138738-pagination-from-results/#findComment-726068 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.