PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 17th, 2012, 05:28 PM
Storm2012 Storm2012 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 10 Storm2012 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 8 sec
Reputation Power: 0
A word of advise please.

I am all new with PHP so bare with me here.

I am writing my first script (well... more application), but I can not seem to figure out how to display the data as I wish. Even after searching google and diving into a lot of online tutorials I am not able to find the answer to my question.

I am able to display all my data on one page. My question is. How would I edit my code so that it display's 10 results and then underneath the results it gives me the option to go to a next page.

Example:
Quote:
previous page 8,9,20....17 next page


The connection to the database is done with the use of an included file. This because I want to store some variables when the connection is made which need to be used in different pages.
PHP Code:
 $sql "SELECT naam, datum_toevoeging, inleg_totaal FROM medewerker_poster";
        
$resultaat mysql_query($sql);
        
$aantal_rijen mysql_numrows($resultaat);
        
mysql_close(); 

The following is used to display the data:
PHP Code:
 $teller 0;
                        while(
$teller $aantal_rijen){
                        
                            
$naam mysql_result($resultaat$teller"naam");
                            
$datum_toevoeging mysql_result($resultaat$teller"datum_toevoeging");
                            
$inleg_totaal mysql_result($resultaat$teller"inleg_totaal");
                        
                            print 
"<tr>
                                        <td>" 
$naam "</td>
                                        <td>" 
$datum_toevoeging "</td>
                                        <td>" 
$inleg_totaal "</td>
                                    </tr>"
;
                            
$teller++;
                        } 

Thanks in advance.

Reply With Quote
  #2  
Old November 17th, 2012, 06:05 PM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 22 h 56 m
Reputation Power: 164
I achieved this with reference to a book: PHP and MySql by Larry Ullman - excellent book.

But there are numerous references to PHP Pagination on the internet.

Essentially you need to store the total number of records, divide this into pages, and use url-get parameters to jump from page to page.
Comments on this post
Storm2012 agrees: Thank you for the help.

Reply With Quote
  #3  
Old November 17th, 2012, 06:09 PM
Storm2012 Storm2012 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 10 Storm2012 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by AndrewSW
I achieved this with reference to a book: PHP and MySql by Larry Ullman - excellent book.

But there are numerous references to ****on the internet.

Essentially you need to store the total number of records, divide this into pages, and use url-get parameters to jump from page to page.


Thank you.

Now I at least have a term for to search.

Reply With Quote
  #4  
Old November 17th, 2012, 06:15 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,833 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 1 h 5 m 18 sec
Reputation Power: 811
Hi,

before you read through the whole code (which doesn't look very good to me):

If you have n entries per page and you want to select the entries for a specific page p, you first skip all entries of the previous pages, which are given by (p - 1) * n. And then you select n rows.

MySQL has a LIMIT clause for this:

Code:
SELECT
...
LIMIT (number of rows to skip), (number of rows to select)


That's all the "magic".
Comments on this post
Storm2012 agrees: Thank you for your help.
npl disagrees!

Reply With Quote
  #5  
Old November 17th, 2012, 06:23 PM
Storm2012 Storm2012 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 10 Storm2012 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Hi,

before you read through the whole code (which doesn't look very good to me):

If you have n entries per page and you want to select the entries for a specific page p, you first skip all entries of the previous pages, which are given by (p - 1) * n. And then you select n rows.

MySQL has a LIMIT clause for this:

Code:
SELECT
...
LIMIT (number of rows to skip), (number of rows to select)


That's all the "magic".

If you mean error checking when connecting to the MySQL database that is done seperatly.

I presume there are way better methods of coding what I did. However as I am just beginning this method allows me to keep good track of my variables and see exactly what I am doing.

I do not really understand what you mean with using the LIMIT clause as I am not familiar with it. However I will do some research on that as well.

Reply With Quote
  #6  
Old November 17th, 2012, 06:33 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,833 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 1 h 5 m 18 sec
Reputation Power: 811
Quote:
Originally Posted by Storm2012
I presume there are way better methods of coding what I did. However as I am just beginning this method allows me to keep good track of my variables and see exactly what I am doing.


I was refering to the code in AndrewSW's link. It does contain good explanations, but the code itself isn't exactly best practices.

You should generall be aware that the mysql_... functions are absolete. See this link for explanations and alternatives:

http://php.net/manual/en/mysqlinfo.api.choosing.php

You don't have to rewrite your whole code now, but you should switch to one of the more modern libraries in the long term.



Quote:
Originally Posted by Storm2012
I do not really understand what you mean with using the LIMIT clause as I am not familiar with it. However I will do some research on that as well.


See the MySQL online manual:

http://dev.mysql.com/doc/refman/5.6/en/select.html
Comments on this post
npl disagrees!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > A word of advise please.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap