?
Solved

divide into pages

Posted on 2000-04-11
7
Medium Priority
?
205 Views
Last Modified: 2010-03-05
i want to write a PERL CGI program that can show 10 records each pages of my database.
i use DBI and mysql.

i would like to show the page numbers in every pages so that a user can click for example 2, then bring him to page2.

i want that the number of pages are automatically calculated in the program.

how to implement this?

how can i get the number of records in my database?
using this value, i can divide it by 10 so that i can get the number of pages.

any one help me?

thanks

Stanley

0
Comment
Question by:stanleyhuen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
olthoff earned 120 total points
ID: 2711801
select count(1) from TABLE; will give you a count of all of the records in the table.

Then to limit your output you do:

select * from TABLE where ? = ? LIMIT 10;

This will limit tour output to 10 rows.  Then you have to create the query so you get the data you want.  I am not sure what it is in MYSQL but probably something like:

select * from TABLE where ROW_ID > ? LIMIT 10;

This will give you your page #.  ? would be Page # * 10
0
 

Author Comment

by:stanleyhuen
ID: 2721427
thanks olthoff,

though i now knowselect count(1) from TABLE; will give me a count of all of the records in the table.

but how to get this number with DBI?
i only know to use
$sth->fetchrow_hashref;

as it will only return a number,
how to get it?

0
 

Author Comment

by:stanleyhuen
ID: 2744528
what is count(1) mean?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:olthoff
ID: 2745007
It counts the number of records, I believe that the (1) is the first field in the table, it really doesn't matter because you want a count.  It is similar to

select count(name) from customer;

as for how to use the DBI, I would suggest reading the documentation, but a simple example (from memory) would be

$db = DBI->connect(db:MYSQL, name, password);
$db->prepare("select count(1) from table");
$db->bind_columns(\$Count);
$db->execute;
#This will get the count into the $Count variable;
$db->fetch;
$db->disconnect;

You can do your other query like this as well.


 


0
 

Author Comment

by:stanleyhuen
ID: 2761853
Adjusted points from 13 to 30
0
 

Author Comment

by:stanleyhuen
ID: 2761854
i often use
$sth->fetchrow_hashref;

i don't know there is $sth->fetch;
what does it mean?

also i seldom use
$sth->bind_columns;


though i have read some doc, but my english is not so good enough to understand well.

would you please explain the above terms in simple english of their usage?

many thanks.

stanley
0
 
LVL 1

Expert Comment

by:olthoff
ID: 2762032
$db = DBI->connect(db:MYSQL, name, password);

# This line connects you to the database


$db->prepare("select count(1) from table");

# This line prepares the SQL statement

$db->bind_columns(\$Count);

# This line will bind any variables that you would like to assign the search results from the SQL

$db->execute;

# This will execute the prepared SQL statement

$db->fetch;

#This will fetch the variable data and assign it to the variables you boud to the columns

$db->disconnect;

# This disconnects you from that database.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question