I have two forms, one used to store fields into a table (let's call it save form) and the other to search (let's call it search form) using one field and prefill the original form with a single record from the database table. I have it working fine with a redirect url and db record loader actions using a single field as the parameter.
Now I want to be able to search using one of two possible fields as the parameter and one field may not always have a value stored in the database. Is this possible and how do I do it? Do I just add the second field as a parameter in the redirect url action on the search form and then add the second field to the db record loader action db field, request parameter and where statements?
Now I want to be able to search using one of two possible fields as the parameter and one field may not always have a value stored in the database. Is this possible and how do I do it? Do I just add the second field as a parameter in the redirect url action on the search form and then add the second field to the db record loader action db field, request parameter and where statements?
Hi mkusens,
I think that you can do it by leaving the DB Field and Request Param boxes of the DB Record Loader empty and using just the WHERE Statement box on the Advanced tab.
The WHERE entry would look like this:
I've used OR here, change that to AND if you want both parameters matched.
Bob
Bob
I think that you can do it by leaving the DB Field and Request Param boxes of the DB Record Loader empty and using just the WHERE Statement box on the Advanced tab.
The WHERE entry would look like this:
<?php
$where = array();
if ( isset($form->data['param_1']) && $form->data['param_1'] != '' ) {
$where[] = " `column_a` = {$form->data['param_1']} ";
}
if ( isset($form->data['param_2']) && $form->data['param_2'] != '' ) {
$where[] = " `column_b` = {$form->data['param_2']} ";
}
$where = implode(' OR ', $where);
echo $where;
?>
I've used OR here, change that to AND if you want both parameters matched.
Bob
Bob
This topic is locked and no more replies can be posted.