Jump to content
Larry Ullman's Book Forums

Pagination?


Recommended Posts

I just received your book and had a question on pagination.

 

How would you handle this when there are hundreds of products?

 

I did not see this addressed.

 

Thanks

 

I posted in comments before realizing I should use the forum.

Link to comment
Share on other sites

Hi Frank,

 

In what way do you mean? In Larry's books he sets the display number, so you decide how many results to show per page. And he gathers the total number of results to decide how many pages of results there will be.

 

Does that help at all?

  • Upvote 1
Link to comment
Share on other sites

Larry covers this in detail in his PHP 6 and MySQL 5 book. The E-Commerce book is somewhat more advanced, and assumes you have these "basics" down. In order to handle pagination though, you basically need to use the LIMIT statement in the MySQL query, and then display the results accordingly using PHP. If this is all new to you, I highly recommend going through Larry's PHP 6 and MySQL 5 book first. It's an excellent primer for the two.

  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...

Larry covers this in detail in his PHP 6 and MySQL 5 book. The E-Commerce book is somewhat more advanced, and assumes you have these "basics" down. In order to handle pagination though, you basically need to use the LIMIT statement in the MySQL query, and then display the results accordingly using PHP. If this is all new to you, I highly recommend going through Larry's PHP 6 and MySQL 5 book first. It's an excellent primer for the two.

I will take a look at this book.

 

In the eCommerce book, I did not see any examples that showed paging through products returned from a search.

if you get a large result-set, this is not practical. I guess I was hoping to see a more complete example.

I still find the book very good.

 

I also just started looking into yii and also use codeigniter.

 

I guess I can apply his examples in one of these frameworks.

Link to comment
Share on other sites

No, I didn't demonstrate pagination in the book, in part because there's only so much space available and in part because pagination is a fairly rudimentary concept to implement. To apply pagination...

- You'd need to create a stored procedure that returns the number of products in that category.

- From that stored procedure, you'd be able to calculate how many pages are required.

- The stored procedure for fetching products would need to be changed to take two more arguments: the number of records to fetch and where to start in the result set.

- The PHP script would need to determine and pass those two arguments to the stored procedure.

- You'd need to create pagination links to subsequent and previous pages that pass the total number of pages involved and where to begin that page's result set.

 

That's the basic idea. Most of this is covered in detail in my PHP & MySQL book, aside from the stored procedure stuff (that book's example uses straight queries for all this). If you have any questions or problems implementing this, let me know. I could write up a blog posting about it, if you'd like (it just may take a while).

Link to comment
Share on other sites

Thanks Larry,

 

I was also looking at your PHP for the Web book.

 

I am trying to decide now if I should jump into yii to do eCommerce rather than code from scratch.

However, I believe I would learn more if I coded from scratch.

Link to comment
Share on other sites

Yes, you would definitely learn more by coding from scratch. Also, the thing with frameworks, is that they make 80% of the work much, much, much easier and the last 20% much, much harder, so it's not a clear net gain sometimes.

Link to comment
Share on other sites

 Share

×
×
  • Create New...