Solved

divide into pages

Posted on 2000-04-11
7
199 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
  • 4
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
olthoff earned 30 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
remove duplicates from the csv file 13 102
Removing permissions on a Cyrus mailbox via a wrapper script 3 88
Perl string filter 5 74
quoting a comma separated list 20 82
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now