1. "Fabrik 4" helpers needed!

    You are invited to join other community members active in coding, maintaining and improving Fabrik. Please visit https://fabrik.help for more information!
    Dismiss Notice

Calc error - Argument number specifier must be greater than zero and less than 2147483647

Discussion in 'Community' started by ontarget, Dec 6, 2022.

  1. ontarget

    ontarget Active Member

    Level: Community
    I have a calc element returning
    PHP:
    $iban = '{aaa_my_profile___iban}';
    //split array into chunks of 4 chars
    $iban = str_split($iban,4);
    //print_r($iban);
    $iban = $iban[1];
    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);
    $myQuery = "SELECT `bic` FROM `aaa_bic` WHERE `bic` LIKE '%$iban%'";
    $myDb->setQuery($myQuery);
    $bic = $myDb->loadResult();
    //var_dump($bic);
    //exit;
    return $bic;
    The var_dump returns a valid string however on form submission i get the error:
    I think it's something to do with the LIKE '%$iban%'"; because when i remove the wildcard % the form submits fine.
    However then calc doesn't output anything because there is no match!
    Any ideas on how to fix this please?
     
  2. lousyfool

    lousyfool Administrator Staff Member

    Level: Community
    Try
    Code (Text):
    $myQuery = "SELECT `bic` FROM `aaa_bic` WHERE `bic` LIKE '%".$iban."%'";
     
     
  3. ontarget

    ontarget Active Member

    Level: Community
    @lousyfool Thanks I changed it to your suggestion and I now get the error
     
  4. lousyfool

    lousyfool Administrator Staff Member

    Level: Community
    I might be wrong, but this looks more like an error from an incorrect translation or language override.
     
  5. ontarget

    ontarget Active Member

    Level: Community
    I tried this too
    PHP:
    $iban = 'IE04IBPSIE123456123456123456';
    //split array into chunks of 4 chars
    $iban = str_split($iban,4);
    //print_r($iban);
    $iban = $iban[1];

    $db = JFactory::getDbo();
    $query = $db
        ->getQuery(true)
        ->select('bic')
        ->from($db->quoteName('aaa_bic'))
        ->where($db->quoteName('bic') . ' LIKE ' . $db->quote('%'. $iban . '%'));


    $db->setQuery($query);
    $result = $db->loadResult();

    return $result;
    I get the Error:
    var_dump returns Null

    This post seems to offer a solution but as I'm on Fabrik4 / joomla 4 the JString class is not recognised so I'm not sure how to make it work
    https://stackoverflow.com/questions/21267795/php-query-search-a-string-in-a-row/21272382#21272382
     
  6. ontarget

    ontarget Active Member

    Level: Community
    Ok I updated my code to below to use:
    substr($iban, 4, 4);
    and improving the where bit:
    where($db->qn('bic') . ' LIKE ' . $db->q('%' . $db->escape($iban, true) . '%', false));

    The var_dump($result); now shows the correct output:):
    string(8) "IPBSIE2D"

    PHP:
    $iban= 'IBPSIE123456123456123456';

    $iban = substr($iban, 4, 4);

    $db = JFactory::getDBO();
    $query = $db->getQuery(true)
                ->select($db->qn('bic'))
                ->from($db->qn('aaa_bic'))
                ->where($db->qn('bic') . ' LIKE ' . $db->q('%' . $db->escape($iban, true) . '%', false));
    $db->setQuery($query);

    $result = $db->loadResult();
    //var_dump($result);
    //exit;

    return $result;
    However when I return the result I now get the 0 error:
    :(
     
  7. milesreid

    milesreid New Member

    Level: Community
    It looks as though the wildcard search string is not being enclosed in quotation marks.

    try

    ->where($db->qn('bic') . ' LIKE ' . '"'. $db->q('%' . $db->escape($iban, true) . '%', false).'"');

    where the quotation marks are single double single (if not clear from the above!)

    The StackOverflow suggests using the quote() function as an alternative
    HTH
     
    ontarget likes this.

Share This Page