[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
RE: [mv] Updating Database Via Checkboxes - SOLVED!
****** message to minivend-users from "Cameron B. Prince" <cbp@InternetExpertsLLC.com> ******
Hi list,
Thanks to some additional perl help from Bill, I was able to get the
checkbox form working that updates multiple rows in a database.
What this does is query a database for all invoices that are set to be
printed = yes. It lists them all with checkboxes by each one. When you check
the checkboxes and submit the form, all the checked invoices are set to be
printed = no.
The most interesting thing about this code is that it uses Minivend's
ability to accept multiple inputs using the same name. Notice how all the
checkboxes are named "printed".
As Bill put it:
It's OK to have the checkboxes all named the same. Minivend sticks
them all together seperated by a NUL byte. That's why we do the
split /'\0'/ to split them apart into a Perl array variable (@printers).
Here's the code:
FORM:
---------
<TABLE CELLSPACING=2 CELLMARGIN=2 BORDER=1 WIDTH=97% align=center>
<FORM ACTION="[process-target secure=1]" METHOD=POST>
<INPUT TYPE=hidden NAME=mv_session_id VALUE="[data session id]">
<INPUT TYPE=hidden NAME=mv_doit VALUE=refresh>
[search-region more=1 search="
ra=yes
st=sql
sq=select * from invoices where to_print = 'yes'
ml=999999
tf=invoice_number
"]
<TR>
<TH ALIGN=CENTER>Printed</TH>
<TH ALIGN=CENTER>Invoice</TH>
</TR>
[search-list]
<TR>
<TD ALIGN=CENTER><input type="checkbox" NAME="printed" value="[item-data
invoices code]"></TD>
<TD ALIGN=LEFT>[item-data invoices invoice_number]</TD>
</TR>
[/search-list]
</table>
<TABLE CELLSPACING=2 CELLMARGIN=2 BORDER=0>
<TR>
<TD><br><input type="SUBMIT" name="mv_click" value="Mark As Printed"></TD>
</TR>
</table>
[set Mark As Printed]
mv_todo=return
mv_nextpage=printed
[/set]
</form>
PAGE printed:
---------
[perl global=1]
my $dbname = 'invoices';
my @printers = split /\0/, $Values->{printed};
my $sql_req = "UPDATE $dbname SET to_print='no' WHERE code = ";
$sql_req .= join(' or code = ', @printers);
$Scratch->{sql_req} = $sql_req;
return "";
[/perl]
[seti update_print_status][query sql="[scratch sql_req]"][/query][/seti]
<font face="Verdana" size="2">
The following invoice(s) have been marked as printed.
<br><br>
<b>
[perl global=1]
my @printers = split /\0/, $Values->{printed};
my $sql_req = "";
$sql_req .= join(' ', @printers);
return $sql_req;
[/perl]
</b>
</FONT>
-----Original Message-----
From: owner-minivend-users@minivend.com
[mailto:owner-minivend-users@minivend.com]On Behalf Of Bill Randle
Sent: Tuesday, June 06, 2000 12:09 PM
To: minivend-users@minivend.com
Subject: Re: [mv] Updating Database Via Checkboxes
****** message to minivend-users from Bill Randle <billr@exgate.tek.com>
******
Cameron,
It would seem to me you could create an SQL query to do this and invoke with
the
[query] tag. Since your "printed" variable will have the list of items to
print, rather than the ones not to print, you;ll need to essentially negate
the
test operation.
Here's an outline of where I'd start:
[perl global=1]
my $dbname = 'yourdbname';
my @printers = split /'\0'/, $Values->{printed};
my $sql_req = "UPDATE $dbname SET to_print='no' WHERE (";
$sql_req .= join(' AND code != ', @printers);
$sql_req .= ")";
$sql_req =~ s/ AND /; # get rid of extra leading AND from join
$Scratch->{sql_req} = $sql_req;
[/perl]
[query sql="[scratch sql_req]"][/query]
"Cameron B. Prince" wrote:
>
> ****** message to minivend-users from "Cameron B. Prince"
<info@InternetExpertsLLC.com> ******
>
> Hi list,
>
> I am using a sql query to display a loop of items in a database like this:
>
> [search-region more=1 search="
> ra=yes
> st=sql
> sq=select * from invoices where to_print = 'yes'
> ml=999999
> tf=invoice_number
> "]
>
> In the search list I have checkboxes for each result like this:
>
> <input type="checkbox" NAME="printed" value="[item-data invoices code]">
>
> So what this does is list all the invoices that are to be printed with
checkboxes by each one.
>
> What I need to do is create a form of some kind that will update the
database and set to_print to 'no' for each checkbox that is checked.
>
> I have had no problems updating Minivend databases when it comes to single
items, but I am stumped as to how to do this multiple field update.
>
> Can anyone provide any ideas?
>
> Thanks,
>
> Cameron
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to
Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list