I have a CGI page with a table which is populated by fetching the data from database, in a word its like a DATAGRID.
And just at the bottom right end of tha Grid I need a link like "First << 1 2 >> Last"
or like" |< < > >| "on clicking which I can navigate to and fro the records. And I am intend to have "10" records per page.
While surfing I got a piece of code which I am going to paste in the code field. But problem is that it displays the paging link something like this "1 2 3 4 5 ..and so on". But I am not willing to have this paging format because the number of records increases the length of the link also goes on increasing. So can this code be modified to the format which I am intending to have? - #!C:\perl\bin\perl.exe
-
-
use CGI::Carp qw(fatalsToBrowser);
-
use DBI;
-
use CGI qw/:standard/;
-
use CGI;
-
use POSIX;
-
print "Content-Type: text/html\n\n";
-
$|++;
-
-
my $env=$ENV{QUERY_STRING};
-
my@env=split(/=/, $env);
-
my $page= $env[1];
-
my ($results_per_page);
-
if (!$limit) {
-
$limit = 0;
-
}
-
my $dbh = DBI->connect(
-
"dbi:SQLite:COMPANY.db",
-
"", "",
-
{
-
RaiseError => 1,
-
AutoCommit => 1
-
}
-
);
-
-
my $query =$dbh->selectall_arrayref('SELECT *
-
FROM Employees');
-
my $count=@$query ;
-
$results_per_page = 3;
-
my $pagesrequired = ceil($count /
-
$results_per_page);
-
-
[... PIECE OF CODE : 1 WHICH I WANT TO GET
-
REPLACED BY CODE:2 MENTIONED BELOW
-
THIS CODE ,
-
for (my $i = 0; $i <= $pagesrequired -1; $i++) {
-
if ($i == 0) {
-
if ($limit == 0) {
-
print "<a href=\"Employees.cgi?&limit=0
-
\">";
-
print $i + 1;
-
print "</a>";
-
}
-
else {
-
print $i + 1;
-
}
-
}
-
-
if ($i > 0) {
-
if ($limit != ($i * $results_per_page)) {
-
print " | <a href=\"Employees.cgi?&limit=";
-
print ($i * $results_per_page);
-
print "\">\n";
-
print $i + 1,"</a>";
-
}
-
else {
-
print " | ", $i + 1;
-
}
-
}
-
} ...]
-
THIS CODE ENCLOSED BETWEEN [.. ..]GIVES THE
-
PAGINATION FORMAT AS "1 2 3 4.SO ON".
-
BUT I NEED TO GET THE FORMAT OF |< < > >| AS
-
THIS CODE BELOW GENERATES...I AM
-
NOT ABLE TO REPLACE THIS CODE WITH THAT OF THE
-
ABOVE ONE, PLEASE HELP ME OUT.
-
-
[...CODE :2
-
WHERE DECLARATONS FOR BELOW ARE AS
-
FOLLOWS...
-
my $pageNum =$query->param('pageNum');
-
unless($pageNum) {
-
$pageNum=1;
-
}
-
my $offset=$query->param('offset');
-
unless($offset) {
-
$offset=3;
-
}
-
AND
-
my $dbh = DBI->connect
-
("dbi:SQLite:DEVICE.db","", "",
-
{
-
RaiseError => 1,
-
AutoCommit => 1
-
}
-
);
-
my $query =$dbh->selectall_arrayref
-
('SELECT * FROM UsersList');
-
my $numOfRec=@$query ;
-
-
my $numofPages = ceil($numOfRec /
-
$offset);
-
-
/*HERE'S THE CODE WHICH I WANT TO
-
REPLACE IN PLACE OF CODE:1*/
-
if ( $pageNum > 0 ) {
-
print q[<td><a href="Employees.cgi?pageNum=1
-
">|<</a></td>];
-
$pageN = $pageNum - 1;
-
print qq[<td><a href="Employees.cgi?
-
pageNum=$pageN"><</a></td>];
-
}
-
else {
-
print q[<td><span
-
class="currentpage">|<</span></td>];
-
print q[<td><span
-
class="currentpage"><</span></td>];
-
}
-
-
if ( $pageNum < ( $numofPages - 1 )) {
-
$pageN = $pageNum + 1;
-
print qq[<td><a href="Employees.cgi?
-
pageNum=$pageN">></a></td>];
-
print qq[<td><a href="Employees.cgi?
-
pageNum=$numofPages">>|</a></td>];
-
}
-
else {
-
print q[<td><span
-
class="currentpage">></span></td>];
-
print q[<td><span
-
class="currentpage">>|</span></td>];
-
} ...] THE END...
-
-
/*REST OF THE CODE AND AN ERROR WHICH I
-
GONA MENTION BELOW AT THAT PARTICULAR
-
LINE */
-
-
my $sth = $dbh->prepare("SELECT
-
EmployeeId,EmployeeName,Address,Company,Role,
-
Branch FROM Employees
-
limit ?,? ");
-
$sth->bind_param(1, undef,SQL_NUMERIC);
-
$sth->bind_param(2, undef,SQL_NUMERIC);
-
Line:64 $sth->execute
-
($page,$results_per_page);
-
/* ERROR:DBD::SQLite::st execute
-
failed: datatype mismatch at C:/Program
-
Files/Apache SoftwareFoundation/Apache2.2
-
/cgi-bin/Employee.cgi line 64.*/
-
-
print start_html('Employee LIST'),
-
table({-border=>'1',width=>'100%'}),
-
Tr({-align=>'CENTER', -valign=>'TOP'},
-
[
-
th(["EmployeeId"
-
,"EmployeeName","Address","Company","Role
-
","Branch "] )
-
]);
-
while (my ($EmployeeId
-
,$EmployeeName,$Address,$Company,$Role,$Branch ) =
-
$sth->fetchrow_array()) {
-
if ($UserName eq "") {
-
$UserName="UNDEF";
-
}
-
print Tr ({-align=>'CENTER',},
-
[
-
td([$EmployeeId
-
,$EmployeeName,$Address,$Company,$Role,
-
$Branch ]),
-
]);
-
}
1 4954 RonB 589
Expert Mod 512MB Sign in to post your reply or Sign up for a free account.
Similar topics
by: dpackwood |
last post by:
Hello,
I have two different scripts that do pretty much the same thing. The main
perl script is on Windows. It runs and in the middle of it, it then calls
out another perl script that then...
|
by: Martin Foster |
last post by:
Hi.
I would like to be able to mimic the unix tool 'uniq' within a Perl script.
I have a file with entries that look like this
4 10 21 37 58 83 111 145 184 226...
|
by: PzYon |
last post by:
Hey 2gether!
I'm trying to execute a PERL script on the web server when the user presses
a button in an ASP.NET Web Application using Visual Basic. The most obvious
solution for me seemed to be...
|
by: Richard Trahan |
last post by:
I want a js function to call a Perl script residing on a server.
The Perl script will return a string, to be used by the js.
Pseudo code:
<script>
stringvar = perlfunc_on_server(stringarg)...
|
by: benwylie |
last post by:
I am running IIS 6.0 on Windows 2003.
I would like to be able to run a perl script from a web page and
include the output.
I have tried doing it with an ssi:
<form action='docsearch.shtml'...
|
by: 8anos |
last post by:
Hello,
I am new at the community and newbie at programming :)
As you may know rapidshare provides a perl script for linux, to upload files at their servers.
You can find the original scripts at...
|
by: kimonp |
last post by:
I am running on windows XP with a fresh install of wamp5 (1.7.2) and mediawiki.
I am trying to call a perl function from within php using proc_open.
The perl script is being executed and...
|
by: IvanIV |
last post by:
Hi All,
I have trouble with embedding a Perl interpreter into a C program. I would like to replace some subroutine in a Perl script without changing this script from my C program. I need...
|
by: happyse27 |
last post by:
Hi All,
I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters?
Two codes below :
a)...
|
by: happyse27 |
last post by:
Hi All,
I am creating the perl script using html form(with embedded javascript inside).
When using this html form with javascript alone, it works where the form validation will pop up...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |