Multiply table prefixes

0

Is there any function in php to replace #_ with multiple table prefixes example Test,test2,test3,test4

->from ( '#__dolar_corrent AS a' )->leftJoin ( '#__users' )
    
asked by anonymous 22.11.2016 / 21:20

1 answer

3

You have this:

str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

Applying to your case:

->from ( str_replace( '#_', 'Test', '#__dolar_corrent AS a' ) ) etc

If you want to number loop for example:

$from = '#__dolar_corrent AS a';
$join = '#__users';
for($i = 1; $i < 5; ++$i) {
    ...
    $pref = 'Test'.$i;
    ->from(str_replace('#_', $pref, $from))->leftJoin(str_replace('#_', $pref, $join));
    ...
}

Remember that this only makes sense if you can not change the prefixes. With concatenation is much simpler:

for($i = 1; $i < 5; ++$i) {
    ...
    $from = 'Test'.$i.'_dolar_corrent AS a';
    $join = 'Test'.$i.'_users';
    ->from($from)->leftJoin($join);
    ...
}

If you want to omit 1 leaving Test, Test2, Test3 as in question, instead of:

'Test'.$i

use:

'Test'.($i>1?$i:'')

in either case.

    
22.11.2016 / 21:57