Multiple Selections with Listbox

Multiple Selections with Listbox

Postby chrisb » Mon Apr 07, 2014 10:04 am

I am using a listbox as one of the criteria for a report. I'd like to allow me/users to select multiple options; however, this isn't working. When I select one option, it works; but when I select multiple criteria using the shift key, the report comes up blank.
chrisb
 
Posts: 12
Joined: Mon Oct 29, 2012 1:48 pm

Re: Multiple Selections with Listbox

Postby admin » Tue Apr 08, 2014 1:54 pm

chrisb,

What is the listbox's hash variable returning?

Steven
admin
Site Admin
 
Posts: 3161
Joined: Mon Jun 15, 2009 9:53 am

Re: Multiple Selections with Listbox

Postby chrisb » Sun Apr 13, 2014 7:01 am

The list box hash variable is returning the id for a table used to create. The first column in the list box is bidder_id, as is the field name. Here's the PHP code:

Code: Select all
CREATE TABLE #TABLE_ID#
SELECT bidder_id, bid_number, CONCAT(bid_firstName, ' ', bid_lastname) FROM bidder
WHERE bidder_id = '#bidder_id#'


I'm trying to create a report that will print a separate page for each database row. I can get reports to work fine with a single entry report, but when I use the list box to select multiple rows, I seem to break things.
chrisb
 
Posts: 12
Joined: Mon Oct 29, 2012 1:48 pm

Re: Multiple Selections with Listbox

Postby massiws » Mon Apr 14, 2014 8:00 am

chrisb,
when you select more then one field with listbox, the returned value is something like "bidder_id1,bidder_id2,bidder_id3".
You have to change the SQL code accordingly.

Max
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: Multiple Selections with Listbox

Postby chrisb » Mon Apr 14, 2014 9:38 am

You'll have to pardon me--I'm not really experienced with this.

I've tried using the WHERE with IN so that the SQL select will pick out the rows that include those from the list in what the hash variable returns.
I started with the above where the the bidder_id column would match one or more than the list box selected. When I used IN, nothing came back. When I used = as above, I could get one to come back, but I couldn't get more than one to come back.
chrisb
 
Posts: 12
Joined: Mon Oct 29, 2012 1:48 pm

Re: Multiple Selections with Listbox

Postby massiws » Mon Apr 14, 2014 5:17 pm

chrisb,
you have to check returning values from listbox before construct your SQL:
Code: Select all
/* Create an array of all returning values in Listbox */
$listbox =  '#bidder_id#';
$ids = explode(',', $listbox);

/* Create SQL with first value in Listbox */
$sql = "CREATE TABLE #TABLE_ID#
  SELECT bidder_id, bid_number, CONCAT(bid_firstName, ' ', bid_lastname) FROM bidder
  WHERE bidder_id = '"
 . $ids[0] . "'";

/* Delete first element and add any further Listbox values */
array_shift($ids);
foreach ($ids as $id) {
  $sql .= " OR bidder_id = '" . $id . "'";
}

/* nuDebug($sql);  uncomment this line to check SQL statement in Setup -> Debug */
nuRunQuery($sql); 


Hope this helps,
Max
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: Multiple Selections with Listbox

Postby achaahaa » Wed Mar 25, 2015 3:19 pm

when you select more then one field with listbox, the returned value is something like "bidder_id1,bidder_id2,bidder_id3".
You have to change the SQL code accordingly.
achaahaa
 
Posts: 1
Joined: Wed Mar 25, 2015 2:53 pm

Re: Multiple Selections with Listbox

Postby admin » Wed Apr 08, 2015 12:52 pm

chrisb,

I have updated the wiki a bit hopefully this helps.

http://wiki.nubuilder.net/index.php/Adding_Objects#Listbox_Tab

Steven
admin
Site Admin
 
Posts: 3161
Joined: Mon Jun 15, 2009 9:53 am


Return to Report Writer