Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Logical question-to upate DB records

by thisisperl (Novice)
on Jun 01, 2004 at 21:20 UTC ( [id://358621]=note: print w/replies, xml ) Need Help??


in reply to Re: Logical question-to upate DB records
in thread Logical question-to upate DB records

Thanks. Yeah I already made changes similar to the ones you suggested-I have modified the design now and have multiple checkboxes and a single Update button.


The changes I made:

-I am now using CGI to retrieve "arrays of values"
-The form now has an update column with check boxes and a single update button for all rows.
-The value of update check box is set to TicketNo, which is my primary autonumber key so the value tells me which records need to be updated:
In the template:
...... <td> <input type="checkbox" name="Update" value="<!-- TMPL_VAR NAME=TicketN +o -->"></td> <td> <!-- TMPL_VAR NAME=TicketNo --></td> <td> <!-- TMPL_VAR NAME=Customer --></td> <td> <!-- TMPL_VAR NAME=UserName --></td> .... <td> <input type="text" value = "<!-- TMPL_VAR NAME=AssignTo -->" name= +"Detail" size="11"></td> .....

So the template will display records returned from the DB-the user can modify the fields displayed in a text box. (mulitple modifiable fields per record)
In the script:
..... @update = $query->param('Update'); @detail = $query->param('Detail'); ........... print "@update\n"; #Returns the ticket numbers for records that need t +o be updated print "@detail\n";#Returns details for ALL displayed records

Sample output is:
@update prints 40001 40003 40006 40007
@detail prints detail1 detail2 detail3 detail4 detail5 detail6 detail7

The question now:
Given two arrays of different lengths, I cannot use the same array index to access corresponding elements from the two arrays.

So how do I associate the right elements (40003 with detail3 and not detail 2)?

Replies are listed 'Best First'.
Re: Re: Re: Logical question-to upate DB records
by IOrdy (Friar) on Jun 02, 2004 at 00:32 UTC
    You could use your TicketNo to modify the name of your value so you have a unique key to search for.
    #!/usr/bin/perl -w use strict; =cut XHTML <td><input type="checkbox" name="update" value="<TMPL_VAR NAME=TicketN +o>" /></td> <td><!-- TMPL_VAR NAME=TicketNo --></td> <td><!-- TMPL_VAR NAME=Customer --></td> <td><!-- TMPL_VAR NAME=UserName --></td> .... <td><input type="text" name="detail_<TMPL_VAR NAME=TicketNo>" value="< +TMPL_VAR NAME=AssignTo>" size="11" /></td> =cut ... my @update = $query->param('update'); foreach my $ticket_no (@update) { my $assign_to = $query->param('detail_'.$ticket_no); next unless defined $assign_to; # do something with $ticket_no => $assign_to; print qq|assign ticket number $ticket_no to $assign_to \n|; }
      yup, that's what I am doing now. Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://358621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-19 00:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found