Discuss A word of advise please. in the PHP Development forum on Dev Shed. A word of advise please. PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 10
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.
Posts: 1,833
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)
Posts: 10
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.
Posts: 1,833
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: