Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding the topics posted in javaranch

 
Prasath Thirumoorthy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

Consider this forum page where we are placing all our queries.In each page there are about 40 questions.The Page no are given below as Page 12345678>> like this when we click on the respective page no it will show the respective page which contains around 40 queries in that page.How this is done using java code or any sql statments ?

Give me example code and detailed explanation in this.

Thanks & Regards
Prasath Thirumoorthy
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, suppose you have a database containing the topics, with one row in a table for each topic.

If you know that you want to display 40 topics per page, you can find out the number of pages by executing an SQL query like this:

SELECT COUNT(*)/40 FROM TOPICS

If you want to select the topics from a specific page, you'll have to specify this in the SQL statement, but unfortunately there is no (AFAIK) standard way to do this in SQL. In MySQL, you can use the LIMIT keyword like this:

SELECT * FROM TOPICS ORDER BY timestamp LIMIT 120,40

This selects 40 rows, beginning with row number 120 that the query itself returns, but as I wrote, it's MySQL specific SQL syntax.

In Oracle you'd have to do things with ROWNUM, and in other databases it works differently again.

So, look it up in the documentation for your particular database.
[ October 19, 2005: Message edited by: Jesper de Jong ]
 
Prasath Thirumoorthy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jesper de Jong
I understood the putting the topics in n no of pages but i couldn't get it the second part.If the user click on the particular page how it wil get the things in on that specific page.Bcos in the second u placed 120 as the beginning row but in the run-time it may vary how it done.This same kind of scenario u could find in Google Search also there u may n no of pages but if we click on particular page it shows the particular page details.Pleae tell me more abt it.

Thanks & Regards,
Prasath Thirumoorthy
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each "1 2 3 4 5" link encodes a starting index; therefore when the link is pressed the server knows where to start the requested page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic