Results Per Page Form Select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
c0mrade
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2008 4:17 am

Results Per Page Form Select

Post by c0mrade »

Hi all,

I have a "problem" with displaying some records. I have a query that returns loads of results about 130 records.. and I want to organize it a bit in form of "Results per page" from select. here is my query :

Code: Select all

$sql="SELECT * FROM members";
$result = mysql_query($sql);
and extracting it

Code: Select all

while($row = mysql_fetch_array($result))
 {
 $id = $row['id'];
 $name = $row['name'];
 $surname = $row['surnname'];
 $points = $row['points'];
 $awarded = $row['awarded'];
 
     echo "<tr>
    <td><div align=\"center\">$id</div></td>
    <td><div align=\"center\">$name</div></td>
    <td><div align=\"center\">$surname</div></td>
    <td><div align=\"center\">$points</div></td>
        <td><div align=\"center\">$awarded</div></td>
</tr>";
      }
any hints how to do it .. or split it in more pages or something ? thank you in advance
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Results Per Page Form Select

Post by jaoudestudios »

There are many ways to do this. Do you want quick and easy or difficult but sexy?!?!

For the quick and easy use LIMIT in your MySql query!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Results Per Page Form Select

Post by califdon »

The word we use to describe what you are asking about is "pagination". Use that word, plus "php", in any search engine and you will find hundreds of references to how to do pagination with php.
c0mrade
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2008 4:17 am

Re: Results Per Page Form Select

Post by c0mrade »

jaoudestudios: Difficult but sexy is better :) if you allocate some time to explain it would be awesome.
califdon: I already did googled "pagination in php" but didn't couldn't do it for some reason ..

Tnx for your replies
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Results Per Page Form Select

Post by jaoudestudios »

Sure, but you need to make a few decisions first. Do you want it to downgrade gracefully?
c0mrade
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2008 4:17 am

Re: Results Per Page Form Select

Post by c0mrade »

I'm not sure that I understand "downgrade gracefully" .. sorry I'm not native speaker ..
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Results Per Page Form Select

Post by jaoudestudios »

I think google will give a better explanation than me. :wink:
c0mrade
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2008 4:17 am

Re: Results Per Page Form Select

Post by c0mrade »

you mean on the "downgrade gracefully" or "results per page" I'm more interested in second .. :banghead:
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Results Per Page Form Select

Post by jaoudestudios »

For downgrade gracefully.

I know you are more interested in the 'results page' but if you want to make it sexy you need to make some decisions before you start.

The question is "Do you want it to downgrade gracefull"?

If not then look into ajax for sexy server-side pagination or javascript for still sexy but client-side pagination.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Results Per Page Form Select

Post by aceconcepts »

I did a quick search and found this http://php.about.com/od/phpwithmysql/ss ... nation.htm

I typed "php pagination" into Google 8O
c0mrade
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2008 4:17 am

Re: Results Per Page Form Select

Post by c0mrade »

I've found that one also but just now I saw "1 of 4
Prev Next" it all fits now I've done what was needed. Thank you I was just tired last night to understand it. Thank you all again for your posts
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Results Per Page Form Select

Post by jaoudestudios »

The opposite of downgrade gracefully is progressive enhancement! Look it up. There are some cool features you can do if users have javascript on but will still work if they dont.
Post Reply