Hy everybody,
I wrote a where statement into a DBmultirecord loader in the way below and it works correctly. What I need is to insert also another condition on a radiobox value. If I add this statement
it doesn't work at all:
This is the previous where condition correctly working without the new condition:
Thank you in advance
Vinc
I wrote a where statement into a DBmultirecord loader in the way below and it works correctly. What I need is to insert also another condition on a radiobox value. If I add this statement
if (!empty($form->data[tipologia])) {
$stringawhere[] = 'tipologia ='.$form->data[tipologia];
}
it doesn't work at all:
This is the previous where condition correctly working without the new condition:
<?php
$stringawhere= array();
if (!empty($form->data[cognome])) {
$stringawhere[] = 'cognome like \'%'.$form->data[cognome].'%\'';
}
if (!empty($form->data[nome])) {
$stringawhere[] = 'nome like \'%'.$form->data[nome].'%\'';
}
if (!empty($form->data[regione])) {
$stringawhere[] = 'regione = '.$form->data[regione];
}
if (!empty($form->data[provincia])) {
$stringawhere[] = 'provincia = '.$form->data[provincia];
}
if (!empty($form->data[comune])) {
$stringawhere[] = 'comune = '.$form->data[comune];
}
if (!empty($form->data[cap])) {
$stringawhere[] = 'cap = '.$form->data[cap];
}
$stringawhere= implode(" AND ", $stringawhere);
echo $stringawhere.' order by cognome,nome';
?>
Thank you in advance
Vinc
Hi benvenuto,
I can only suspect that either you are missing some quotes - or there is no value set for something and that is throwing an error. Adding a Debugger action should show the query created so that you can debug it.
Here's how I might write it:
Bob
I can only suspect that either you are missing some quotes - or there is no value set for something and that is throwing an error. Adding a Debugger action should show the query created so that you can debug it.
Here's how I might write it:
<?php
$stringawhere= array();
$inputs_array = array(
'cognome',
'nome',
'regione',
'provincia',
'comune',
'cap',
'tipologica'
);
foreach ( $inputs_array as $v ) {
if (isset($form->data[$v]) && $form->data[$v] ) {
$stringawhere[] = "`{$v}` LIKE '%{$form->data[$v]}%'";
}
}
if ( count($stringawhere) ) {
$stringawhere = implode(" AND ", $stringawhere);
echo " {$stringawhere} ORDER BY `cognome`, `nome` ';
} else {
// I'm not sure if this is needed?
echo '1 = 1',
}
?>
Bob
This topic is locked and no more replies can be posted.