Solved

divide into pages

Posted on 2000-04-11
7
200 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

785 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