Log in | Register | Lost password

Bottom
Filter enhancement when using 'like'
  • Posted: 09.09.2005, 06:44
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    Jorn,

    I thought I'd share this code snippet in hopes that it may be added to Pagesetter's parseFilter(). It allows more robust 'like' criteria.

    (e.g. give publist where 'name' begins with [aA])
    .....
    $letter = pnVarCleanFromInput('letter');

    if (isset($letter)) {
    $filterSet = array('filter' => 'name:like:'.$letter.'*',
    'filter2' => 'name:like:'.strtolower($letter).'*');
    }
    .....



    in function pagesetter_userapi_parseFilter($args)...

    changed:
    else if ($operator == 'like')
    {
    if (preg_match('/\*/', $value)) {
    $newvalue = preg_replace('/\*/', '%', trim($value));
    $sql .= "$columnName LIKE '" . pnVarPrepForStore($newvalue) . "'";
    } else {
    // Default mode
    $sql .= "$columnName LIKE '%" . pnVarPrepForStore($value) . "%'";
    }
    }


    Thanks,
    -Joe
  • Posted: 09.09.2005, 07:26
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    Please add it on SourceForge - that improves the likelihood that I'll remember it. It's a good idea.
  • Posted: 07.10.2005, 19:41
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    Is it possible to add some preg_replace code in the

    Quote

    function pagesetter_userapi_parseFilter($args)
    before the line

    Quote

    $sql .= "$columnName LIKE '%" . pnVarPrepForStore($value) . "%'";

    to enable the user to add AND and OR statements to their filters?
    What I have in mind is that the user can create complex queries in a single input field for a more advanced document search. The extra code he should be able to put might look like a ".a" for AND, which then would be replaced by "%' AND $columnName LIKE '%". I have tried to build that code but have not enough skill to get it running.
    Another thing I am interested in is a function to return the search string to the input field, so the user can reuse his filter and modify it without having to type it all again. Hope you can help me!

Template courtesy of Designs By Darren.