tags:

views:

67

answers:

2

Hello every1, i have issue regarding Paging using filterexpression. here's the piece of code for filtering :

     if ( $q->param("Filter") )
        {
        $Id=$q->param('User_Id');
        $Name=$q->param('User_Name');

       if ($Id ne "" )
            {
          $filterexpression= $filterexpression." UserId like '" .$Id. "%' and " ;
             }
        if ($Name ne "" )
          {
        $filterexpression= $filterexpression." UserName like '" .$Name. "%' and " ;
           }
          }
        $filterexpression= $filterexpression. " UserId > 0"  

and here's chunk of the paging code:

    print qq[<td><a href="UsersList.cgi?
     pageNum=$pageN&limit=$limit&SortBy=$SortBy&SortOrder=$SortOrder">&lt;</a></td>];

THE ISSUE IS I WANT TO PUT THE FILTER EXPRESSION IN THIS HREF AFTER SORTORDER VARIABLE,so that after filtering when i go for paging then only those records confined to the filter expression should be shown. I tried to merge this way..

           print qq[<td><a href="UsersList.cgi?
            pageNum=$pageN&limit=$limit&SortBy=$SortBy&SortOrder=$SortOrder
             &Filter=$filterexpression">&lt;</a></td>];

but in url i got to see something like this:

            http://localhost/cgi-bin/UsersList.cgi?
              pageNum=1&limit=3&SortBy=UserId&SortOrder=Asc&filter=%20%20UserId%20like%
              20'1%'%20and%20%20UserId%20>%200

Later i tried to put the "$Id" value in a varible like :

             $string =~ m/^$Id/;  

but when i tried printing this variable i got nothing. Please do help me out with a solution.Thank you.

+1  A: 

I think you just need to escape the output of your variables. URLs reserve certainvariables % being one of them, so you end up requesting something different than you are expecting. change your link output code to be the following:

$limitEnc = urlencode($limit);
$pageNEnc = urlencode($pageN);
$SortByEnc = urlencode($SortBy);
$SortOrderEnc = urlencode($SortOrder);
$filterexpressionEnc = urlencode($filterexpression);
print qq[<td><a href="UsersList.cgi?
            pageNum=$pageNEnc&limit=$limitEnc&SortBy=$SortByEnc&SortOrder=$SortOrderEnc&Filter=$filterexpressionEnc">&lt;</a></td>];
Matt Fellows
SUSH
It's spelled [`uri_escape`](http://p3rl.org/URI::Escape).
daxim
A: 

I'm not sure if you're storing your variable right. This line is a search:

$string =~ m/^$Id/;

This is trying to search the $string for the $Id given.

If you wanted to 'put the $Id value in a varible' like you said, it would look like this:

$string = $Id;
Sho Minamimoto
But if i put this value then i am going to get the record confined to only this value.I mean to say "if i give 1 then according to the above syntax i will get the records confined to userId 1,BUT I WANT THE RECORDS WHOSE USERID STARTS FROM 1(LIKE 1,10,11,12..SO ON)..
SUSH