Page 7 of 7

Re: Guidance needed creating multi-criteria search form with subform

Posted: Wed Feb 15, 2023 1:28 pm
by Keith-i
Brilliant, all working beautifully. Thanks ever so much.

Is there any way to get the 2 secondary iframes to be refreshed/cleared when I hit my reset button?

Re: Guidance needed creating multi-criteria search form with subform

Posted: Wed Feb 15, 2023 1:35 pm
by kev1n
Add the following function to the Custom Code of the frm_propsearch form.

Code: Select all

function resetIframes() {
   
     let f = $("#iframe_instructionslist")[0].contentWindow; 
     f.nuSetProperty('Propertyid', ''); // Set a hashcookie
     f.nuGetBreadcrumb(); // refresh the iframe

     f = $("#iframe_enquirieslist")[0].contentWindow;
     f.nuSetProperty('Propertyid', '');
     f.nuGetBreadcrumb();

}

Then call

Code: Select all

resetIframes();
in your reset's button onclick event.

Re: Guidance needed creating multi-criteria search form with subform

Posted: Tue Feb 21, 2023 10:25 am
by Keith-i
I wonder if you could just help me out again with a bit of code to get my filters to search based on a date range. I have two input objects in which I can select a date. These are given the hash names datefrom_fltr and dateto_fltr. Where I'm struggling is the additional code required in the BB of the iframe to filter the results based on theses dates. My existing BB code with the other filter boxes is below

Code: Select all

$filter = ' AND (1 = 1) ';

setFilter($filter, 'proptype_fltr', 'Type');
setFilter($filter, 'propstyle_fltr', 'Style');
setFilter($filter, 'location_fltr', 'Location');
setFilter($filter, 'beds_fltr', 'Bedrooms');
setFilter($filter, 'seaview_fltr', 'Seaview');
setFilter($filter, 'integral_fltr', 'Integral');
//add datefrom_fltr and dateto_fltr here?

function setFilter(&$filter, $filterName, $columnName) {
    $value = nuGetProperty($filterName);
    if ($value != '') $filter .= " AND $columnName LIKE '%$value%' ";
//add extra code here to search on date range?
}
$create = "CREATE TABLE #TABLE_ID# ";

$select = "

SELECT
 tblInstructions.*,
    tblProperties.*,
    tblRoads.*

FROM
    tblInstructions
        LEFT JOIN tblProperties ON tblProperties.idProperties = tblInstructions.id_Properties
        LEFT JOIN tblRoads ON tblRoads.idRoads = tblProperties.id_Roads

WHERE (1 = 1)

" . $filter;

// To output the SQL to nuDebug Results:
// nuDebug($select);
nuRunQuery($create . $select);
 

Re: Guidance needed creating multi-criteria search form with subform

Posted: Tue Feb 21, 2023 10:40 am
by kev1n
Add the new setDateFilter() function from below and call it like this:

Code: Select all

setDateFilter($filter, 'datefrom_fltr', 'dateto_fltr', 'HERE_YOUR_DATE_COLUMN');

Code: Select all

function setDateFilter(&$filter, $dateFilter1, $dateFilter2, $dateColumn) {
    $date1 = nuGetProperty($dateFilter1);
    $date2 = nuGetProperty($dateFilter2);
    if ($date1 != '' && $date2 != '') {
        $filter .= " AND (`$dateColumn` BETWEEN `$date1` AND `$date2`) ";
    }
}

The expected date format is yyyy-mm-dd. If your date fields have another format, you need to format it in JavaScript like:

Code: Select all

frame.nuSetProperty('datefrom_fltr', $('#your_date_object_id').nuRemoveFormatting());

All untested. If you encounter an issue, uncomment the nuDebug(); line in the code and paste the generated SQL in the forum.

Re: Guidance needed creating multi-criteria search form with subform

Posted: Tue Feb 21, 2023 4:48 pm
by Keith-i
Thanks, I'll give it try.

Re: Guidance needed creating multi-criteria search form with subform

Posted: Wed Feb 22, 2023 2:42 pm
by Keith-i
Ok, heading in the right direction but getting an error on debug

Code: Select all

globeadmin

===PDO MESSAGE===

SQLSTATE[42S22]: Column not found: 1054 Unknown column '2023-02-02' in 'where clause'

===SQL===========

CREATE TABLE ___nu163f61ae843b0a___ 

SELECT
 tblInstructions.*,
    tblProperties.*,
    tblRoads.*

FROM
    tblInstructions
        LEFT JOIN tblProperties ON tblProperties.idProperties = tblInstructions.id_Properties
        LEFT JOIN tblRoads ON tblRoads.idRoads = tblProperties.id_Roads

WHERE (1 = 1)

 AND (1 = 1)  AND Type LIKE '%1%'  AND (`Date` BETWEEN `2023-02-02` AND `2022-02-02`) 
Is it perhaps some syntax around the dates?

Re: Guidance needed creating multi-criteria search form with subform

Posted: Wed Feb 22, 2023 2:50 pm
by kev1n
Use single quotes instead of backticks around the date columns:

Code: Select all

function setDateFilter(&$filter, $dateFilter1, $dateFilter2, $dateColumn) {
    $date1 = nuGetProperty($dateFilter1);
    $date2 = nuGetProperty($dateFilter2);
    if ($date1 != '' && $date2 != '') {
        $filter .= " AND (`$dateColumn` BETWEEN '$date1' AND '$date2') ";
    }
}

Re: Guidance needed creating multi-criteria search form with subform

Posted: Wed Feb 22, 2023 3:13 pm
by Keith-i
Beautiful, thanks!