Well, discovered a problem.
When the search field (hash variable) is empty (no search criteria) no records are found.
If I add a leading 0 to the hash variable used as filter in two different ways like here:
http://forums.nubuilder.cloud/viewtopic.p ... r&start=10 I get these results:
1. either the filter does not work but the field can be empty WHERE p.prim_name = 0#SrcPriName# or
2. sql error WHERE p.prim_name = 0'#SrcPriName#'
So how can I handle empty hash variables? Adding some additional code before the sql is executed?
BR, Tinka
Welcome to the nuBuilder forums!
Please register and login to view forums and other content only available to registered users.
Please register and login to view forums and other content only available to registered users.
advanced search - browse table and filter
-
- Site Admin
- Posts: 2781
- Joined: Mon Jun 15, 2009 2:23 am
- nuBuilder Version: 4.5
- Been thanked: 1 time
Re: advanced search - browse table and filter
Tinka,
You will need to get the latest build (Shane has explained how to do that here.. http://forums.nubuilder.cloud/viewtopic.php?f=17&t=8449 )
There is another way to use hash variables. nuSetHash(name, value) will allow you to create hash variables that are not a field value from a table.
Steven
You will need to get the latest build (Shane has explained how to do that here.. http://forums.nubuilder.cloud/viewtopic.php?f=17&t=8449 )
There is another way to use hash variables. nuSetHash(name, value) will allow you to create hash variables that are not a field value from a table.
Steven
-
- Posts: 73
- Joined: Mon Feb 24, 2014 2:58 pm
Re: advanced search - browse table and filter
Steven,
Yes, I have the newest build.
I don't understand what you are suggesting to do by
I am looking for your advice in how to re-use some of the NuBuilder search field code that accounts for this case (function nuGetBrowseRecords($f, $p, $hashData) of nuapi.php file) OR
help to build a php function like in this example:
http://stackoverflow.com/questions/1857 ... s-supplied
BR, Tinka
Yes, I have the newest build.
I don't understand what you are suggesting to do by
I try to find a way to rebuild the WHERE clause when my search fields are left empty - meaning the hash variables are not set/null.There is another way to use hash variables. nuSetHash(name, value) will allow you to create hash variables that are not a field value from a table.
I am looking for your advice in how to re-use some of the NuBuilder search field code that accounts for this case (function nuGetBrowseRecords($f, $p, $hashData) of nuapi.php file) OR
help to build a php function like in this example:
http://stackoverflow.com/questions/1857 ... s-supplied
BR, Tinka
-
- Posts: 11
- Joined: Sun May 11, 2014 9:18 am
- Location: France
Re: advanced search - browse table and filter
Hi,
I've not tested but you may use MySQL IF statement in WHERE clause:
Something such as : WHERE IF('#SrcPriName#' != '',p.prim_name = '#SrcPriName#', 1)
If #SrcPriName# is empty, the clause is WHERE 1, else the clause is WHERE p.prim_name = '#SrcPriName#'
No more trick with the 0 preceding your hash variable.
I've not tested but you may use MySQL IF statement in WHERE clause:
Something such as : WHERE IF('#SrcPriName#' != '',p.prim_name = '#SrcPriName#', 1)
If #SrcPriName# is empty, the clause is WHERE 1, else the clause is WHERE p.prim_name = '#SrcPriName#'
No more trick with the 0 preceding your hash variable.
-
- Site Admin
- Posts: 2781
- Joined: Mon Jun 15, 2009 2:23 am
- nuBuilder Version: 4.5
- Been thanked: 1 time
Re: advanced search - browse table and filter
Tinka
(if #SrcPriName# = '')
1 WHERE p.prim_name = 0
2 WHERE p.prim_name = 0''
(if #SrcPriName# = 'bob')
1 WHERE p.prim_name = 0bob
2 WHERE p.prim_name = 0'bob'
but this should work..
WHERE '0' = '0#SrcPriName#'
Steven
The results of 1 and 2 are because you will literally get this..Tinka wrote:1. either the filter does not work but the field can be empty WHERE p.prim_name = 0#SrcPriName# or
2. sql error WHERE p.prim_name = 0'#SrcPriName#'
(if #SrcPriName# = '')
1 WHERE p.prim_name = 0
2 WHERE p.prim_name = 0''
(if #SrcPriName# = 'bob')
1 WHERE p.prim_name = 0bob
2 WHERE p.prim_name = 0'bob'
but this should work..
WHERE '0' = '0#SrcPriName#'
Steven
-
- Posts: 73
- Joined: Mon Feb 24, 2014 2:58 pm
Re: advanced search - browse table and filter
Fat115,
Thank you for your suggestion - it works!
So far, I have tested three concurrent WHERE IF statements in my sql and they work like they are supposed to ( I can leave any/all of the three fields empty).
So on Before Browse i have:
And on the form sql I just have
Steven, I have not tested your solution.
BR, Tinka
Thank you for your suggestion - it works!
So far, I have tested three concurrent WHERE IF statements in my sql and they work like they are supposed to ( I can leave any/all of the three fields empty).
So on Before Browse i have:
Code: Select all
$sql = "
Create table #TABLE_ID#
Select p.*,chr.*, gp.*, g.*
from primer p
Left join gene g ON g.gene_id = p.pri_gene_idFK
Left join genomic_position gp ON gp.genpos_id = p.pri_genpos_idFK
Left join chromnr chr ON chr.chromnr_id = gp.genpos_chrnr_idFK
WHERE IF('#SrcPriName#' != '',p.prim_name = '#SrcPriName#', 1) AND
IF('#Find_gene#' != '',g.gene_id = '#Find_gene#',1) AND
IF('#Findchr_nr#' != '',gp.genpos_chrnr_idFK = '#Findchr_nr#', 1)
";
nuDebug($sql);
$q = nuRunQuery($sql);
Code: Select all
Select * from #TABLE_ID#
BR, Tinka