Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/138738-pagination-from-results/
Share on other sites

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

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.

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.