Browse Table Filter Options

Questions related to using nuBuilder Forte.

Re: Browse Table Filter Options

Postby Alohajoe5 » Tue May 07, 2019 4:47 am

Let me correct this...actually it does appear that it is updating the records based off of the "Word" dropdown, only it's not limiting the records to those=2 when "2" is selected in the dropdown. Further, when "32" is selected in the dropdown--nothing is displayed even though there are records with 32 in the Word column
Alohajoe5
 
Posts: 46
Joined: Tue Apr 16, 2019 9:02 pm

Re: Browse Table Filter Options

Postby Alohajoe5 » Tue May 07, 2019 4:53 am

kev1n wrote:This is what it should look like:

Code: Select all
SELECT * FROM Channels

WHERE

((Word = '#nuBrowseTitle0_dropdown#' AND LOCATE('#', '#nuBrowseTitle0_dropdown#') <> 1 )
    OR '#nuBrowseTitle0_dropdown#' = '' OR LOCATE('#', '#nuBrowseTitle0_dropdown#') = 1)
AND

((Type  = '#nuBrowseTitle1_dropdown#' AND LOCATE('#', '#nuBrowseTitle1_dropdown#') <> 1 )
    OR '#nuBrowseTitle1_dropdown#' = '' OR LOCATE('#', '#nuBrowseTitle1_dropdown#') = 1)



Note that there is no final semicolon (;)



Solved it. The problem was in the references to nuBrowseTitle0 etc...They needed to reference the index of the column not the vardata0, 1, 2 etc. Thus even though Word was the first column with a dropdown, it was index 3. This solved this issue. Now onto dynamically populating the dropdowns! Thanks
Alohajoe5
 
Posts: 46
Joined: Tue Apr 16, 2019 9:02 pm

Re: Browse Table Filter Options

Postby kev1n » Tue May 07, 2019 4:54 am

Can you upload a picture of your table title names (of the Browse screen)?
kev1n
 
Posts: 183
Joined: Mon Oct 15, 2018 2:13 am

Re: Browse Table Filter Options

Postby Alohajoe5 » Wed May 08, 2019 2:31 am

kev1n wrote:Can you upload a picture of your table title names (of the Browse screen)?


Unfortunately I can't do that, however I can list them (From the SQL Table):

channel_names, short_names, web_address, word, number, offset, resolution, digital, type, format, channel

The dropdowns are only on: word, number, offset & channel....
The tables have the same names displayed in nubuilder, except they are uppercase.

Thanks
Alohajoe5
 
Posts: 46
Joined: Tue Apr 16, 2019 9:02 pm

Re: Browse Table Filter Options

Postby kev1n » Wed May 08, 2019 2:50 am

If this is the order of your columns, then the indexes are not correct:

channel_names, short_names, web_address, word, number, offset, resolution, digital, type, format, channel

word ---> column nr. 4 = index 3
number ---> column nr. 5 = index 4

Code: Select all
var data3 = ["", "input", "word", "image"]; // static values to be added to the dropdown   
    addBrowseTitleDropDown(3, data3);

    var data4 = ["", "text", "nuDate", "nuScroll"]; // static values to be added to the dropdown   
    addBrowseTitleDropDown(4, data4);


And also the sql must be changed:


SELECT * FROM Channels

WHERE

Code: Select all
((word = '#nuBrowseTitle3_dropdown#' AND LOCATE('#', '#nuBrowseTitle3_dropdown#') <> 1 )
    OR '#nuBrowseTitle3_dropdown#' = '' OR LOCATE('#', '#nuBrowseTitle3_dropdown#') = 1)
AND

((number  = '#nuBrowseTitle4_dropdown#' AND LOCATE('#', '#nuBrowseTitle4_dropdown#') <> 1 )
    OR '#nuBrowseTitle4_dropdown#' = '' OR LOCATE('#', '#nuBrowseTitle4_dropdown#') = 1
kev1n
 
Posts: 183
Joined: Mon Oct 15, 2018 2:13 am

Re: Browse Table Filter Options

Postby Alohajoe5 » Wed May 08, 2019 2:57 am

Yep. It's working great with the static values! Column/indexes all written correctly. This appears to be the same javascript for the static values though. How would I go about dynamically populating that list with unique values from the column?
Alohajoe5
 
Posts: 46
Joined: Tue Apr 16, 2019 9:02 pm

Re: Browse Table Filter Options

Postby kev1n » Wed May 08, 2019 3:13 am

Alohajoe5 wrote:Yep. It's working great with the static values! Column/indexes all written correctly. This appears to be the same javascript for the static values though. How would I go about dynamically populating that list with unique values from the column?


Example to populate distinct values of the word column:

You need to write a PHP script that retrieves the values from the db. Add this to PHP BB (Before Browse).

Code: Select all
function sqlWords() {
    return "SELECT DISTINCT word FROM Channels";
}

function getBase64JsonDTString($sql) {
   $result = nuRunQuery($sql);
   $a = array();
   while ($row = db_fetch_row($result)) {
     $a[] = $row;
   }
   return base64_encode(json_encode( $a ));
}

$w = getBase64JsonDTString(sqlWords());


$js = "
   function getWords() {
      return atob('$w');
   }
";

nuAddJavascript($js);


Then in Javascript, instead of assigning a static array, you pass the getWords function:

Code: Select all
var data3 =  JSON.parse(getWords());
addBrowseTitleDropDown(3,data3);
kev1n
 
Posts: 183
Joined: Mon Oct 15, 2018 2:13 am

Re: Browse Table Filter Options

Postby Alohajoe5 » Wed May 08, 2019 11:36 pm

I'll post what my code in a little bit, but the problem I'm having right now is the code, as edited, no longer displays the drop-downs.
Alohajoe5
 
Posts: 46
Joined: Tue Apr 16, 2019 9:02 pm

Re: Browse Table Filter Options

Postby Alohajoe5 » Thu May 09, 2019 4:14 am

Ok, I've got the PHP, Javascript, & SQL all playing nice with each other; however, I am left with two final issues:

1.) The items in the dropdown are randomly ordered (likely by first instance in the db table). I tried adding: ORDER BY ASC in the PHP under the SELECT DISTINCT word FROM Channels, but this didn't seem to work.

2.) Once a selection is made in one of the dropdown menus, there is no ability to go back to viewing all records, you can simply change to viewing another individual record. I tried adding push("") in the javascript and an include () in the PHP, however neither gave me a "All" option that would have cleared the selection in the dropdown.

Thanks
Alohajoe5
 
Posts: 46
Joined: Tue Apr 16, 2019 9:02 pm

Re: Browse Table Filter Options

Postby Alohajoe5 » Thu May 09, 2019 5:34 am

I've solved these issues, I will post the code in a bit for anyone else who might be interested in this topic.
Alohajoe5
 
Posts: 46
Joined: Tue Apr 16, 2019 9:02 pm

PreviousNext

Return to General