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

ontarget

Active Member
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:
0
Argument number specifier must be greater than zero and less than 2147483647
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?
 
Try
Code:
$myQuery = "SELECT `bic` FROM `aaa_bic` WHERE `bic` LIKE '%".$iban."%'";
 
I might be wrong, but this looks more like an error from an incorrect translation or language override.
 
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:
0 Unknown format specifier "$"
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
 
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:
0
Unknown format specifier " "
:(
 
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
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top