RE: Changing row color with subroutine - a shortcut...
I rememeber sometimes doing something like this when using CGI.pm and DBI.pm push(@rows,td({-colspan=>'6',-bgcolor=>'#FF'},[$th])); #blank row $th = ' '; push(@rows,td({-colspan=>'6',-bgcolor=>'#FF'},[$th])); push(@rows,td({-bgcolor=>'#FFCC99'},['',b('Verwijderen:'),b('Naam:'),b('Voornaam:'),b('Vertegenwoordiger:*'),b('Bekijk CV:')])); while (@data = $cursor->fetchrow) { $count++; if ($count % 2 == 0){ $bgcolor = "#FFCC99"; }else{ $bgcolor = "#FF"; } etc.. and then i the end i printed the table $innertable = table({-border=>'0',-width=>'100%', -cellspacing=>'1', -cellpadding=>'2', -bgcolor=>'#FF'},Tr(\@rows)); I always founded this a very nice feature of CGI.pm. The only thing i never found out is how you could manipulate tables in this same kind of way ? Thanks, Dirk --- Peter Kappus <[EMAIL PROTECTED]> wrote: > Another neat trick I use to get subroutine arguments > is the old "shift" > function without an argument. > > Since, @_ is the default array in a subroutine you > can just say > > my $firstParm = shift; #shift off the first arg from > @_ > > > Therefore, > > print add(30,50); > > sub addTwo{ > my $firstNum = shift; > my $secondNum = shift; > return $firstNum + $secondNum; > } > > will print "80". neato eh? > > another fun trick if you have, say, 3 arguments is > to say > > my ($name, $size, $color) = @_; > > this will map the first three args in your args > array two the variables > $name, $size, and $color. > > I hope this is useful... > > -PK > > -Original Message- > From: zentara [mailto:[EMAIL PROTECTED]] > Sent: Friday, November 22, 2002 6:33 AM > To: [EMAIL PROTECTED] > Subject: Re: Changing row color with subroutine > > > On Fri, 22 Nov 2002 03:28:39 -0800, > [EMAIL PROTECTED] (Poster) wrote: > > >Hi, I am having a little trouble with a sub that is > using the modulus > >operator. > > Yeah, it fooled me too for a bit :-) > The problem is the way you pass the value to the > sub, @_ always is 1, the count of elements in @_. > Change @_ to @_[0] or better yet $_[0] > > >--here is the sub > >sub color_rows > >{ > >my $num = @_; > > > -- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > __ Do you Yahoo!? Yahoo! Mail Plus Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: arrays & lists
First I need to tell you that I am not a MySQL specialist and my opinion might be wrong butI think that: 1. You'll better use where day=$day and where month=$month because it works faster than using the "like" operator. 2. I think MySQL has a function for returning random numbers, so you better use that function instead. It will return a single row that match a criteria from the database and not a lot of records that need to be processed by Perl after that. You might check MySQL documentation for finding out this function. What you want, I think that it can be made with a single SQL line and you will need to get the data from a single row using Perl. Teddy, Teddy's Center: http://teddy.fcc.ro/ Email: [EMAIL PROTECTED] - Original Message - From: "Al Hospers" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 22, 2002 11:03 PM Subject: arrays & lists hi I know I am missing a lot in my knowledge, but I'm trying to figure something out & seemingly am in a hole... the task is as follows: 1) query a mysql database for as many records as match a criteria (I can do this OK) 2) put the resulting records, how ever many there are, into a list or an array 3) count the number of records I have retrived (I can do this OK) 4) choose a random record number (I can do this) 5) get the record corresponding to the random record number from the array 6) get a particular field from the stored record I am using DBI to get the data from the database. here is what I have so far: sub getRandomRecord{ my $cgi = shift; my $dbh = shift; my $month = shift; my $day = shift; my $searchResult; my $returnValue; #prepare and execute SQL statement $sqlstatement = "SELECT * FROM $TABLE WHERE month like $month and day like $day"; $sth = executeSQLStatement($sqlstatement, $dbh); $counter = 0; # put the records returned in an array/list & count how many while ($searchResult = $sth->fetchrow_array() ) { # get the 4th field from the record in the array & put it in the list my @list = ($searchResult[3]); ++$counter; } # pass the counter to the random integer routine & get a value back my $randomNumber = getRandomNumber($counter); $returnValue = @list[$randomNumber]; # clean up the DBI $sth->finish(); return $returnValue } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Changing row color with subroutine - a shortcut...
Another neat trick I use to get subroutine arguments is the old "shift" function without an argument. Since, @_ is the default array in a subroutine you can just say my $firstParm = shift; #shift off the first arg from @_ Therefore, print add(30,50); sub addTwo{ my $firstNum = shift; my $secondNum = shift; return $firstNum + $secondNum; } will print "80". neato eh? another fun trick if you have, say, 3 arguments is to say my ($name, $size, $color) = @_; this will map the first three args in your args array two the variables $name, $size, and $color. I hope this is useful... -PK -Original Message- From: zentara [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 6:33 AM To: [EMAIL PROTECTED] Subject: Re: Changing row color with subroutine On Fri, 22 Nov 2002 03:28:39 -0800, [EMAIL PROTECTED] (Poster) wrote: >Hi, I am having a little trouble with a sub that is using the modulus >operator. Yeah, it fooled me too for a bit :-) The problem is the way you pass the value to the sub, @_ always is 1, the count of elements in @_. Change @_ to @_[0] or better yet $_[0] >--here is the sub >sub color_rows >{ >my $num = @_; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
multiple selection
Hello all, having a problem with processing multiple selection from a scrolling list... first time working with tha scrolling list. Here is the test script I'm working with: #!/usr/local/bin/perl use CGI qw(:standard); $action = param('action'); print header(); print start_html(); if (!$action) { print start_html(); print qq~ Select List: ~; print scrolling_list(-name=>'list', -value=>['List_1','List_2','List_3'], -default=>['List_1'], -multiple=>1); print qq~ ~; print end_html(); } else { @lists = split(/ /,param('list')); print qq|Total: @lists|; } exit(); Now I thought that the @list array would store all the selected values from the list... but it doesn't, just one, even if all the items have been selected from the list... what am I missing here ?? thanks -- MikeBlezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! http://www.thunder-rain.com Tel: 1(985)902-8484 MSN: [EMAIL PROTECTED] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
arrays & lists
hi I know I am missing a lot in my knowledge, but I'm trying to figure something out & seemingly am in a hole... the task is as follows: 1) query a mysql database for as many records as match a criteria (I can do this OK) 2) put the resulting records, how ever many there are, into a list or an array 3) count the number of records I have retrived (I can do this OK) 4) choose a random record number (I can do this) 5) get the record corresponding to the random record number from the array 6) get a particular field from the stored record I am using DBI to get the data from the database. here is what I have so far: sub getRandomRecord{ my $cgi = shift; my $dbh = shift; my $month = shift; my $day = shift; my $searchResult; my $returnValue; #prepare and execute SQL statement $sqlstatement = "SELECT * FROM $TABLE WHERE month like $month and day like $day"; $sth = executeSQLStatement($sqlstatement, $dbh); $counter = 0; # put the records returned in an array/list & count how many while ($searchResult = $sth->fetchrow_array() ) { # get the 4th field from the record in the array & put it in the list my @list = ($searchResult[3]); ++$counter; } # pass the counter to the random integer routine & get a value back my $randomNumber = getRandomNumber($counter); $returnValue = @list[$randomNumber]; # clean up the DBI $sth->finish(); return $returnValue } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Changing row color with subroutine
On Fri, 22 Nov 2002 03:28:39 -0800, [EMAIL PROTECTED] (Poster) wrote: >Hi, I am having a little trouble with a sub that is using the modulus >operator. Yeah, it fooled me too for a bit :-) The problem is the way you pass the value to the sub, @_ always is 1, the count of elements in @_. Change @_ to @_[0] or better yet $_[0] > >It is called here-within a while loop: >while (my $row = $sth->fetchrow_hashref()) { > count++; > color_rows( $count ) > --some other stuff > table cell value > -some other stuff >} >--here is the sub >sub color_rows >{ >my $num = @_; my $num = $_[0]; >my $bgcolor; > >If ( $num % 2 == 0 ) { > $bgcolor="#bde6de"; >} else { > $bgcolor="white"; >} >return $bgcolor; >}#end sub > >I expect that when the value that is passed in $count is even it will >set the row color green, otherwise it will set it to white. What it is >actually doing is setting the value white every time. > >Thanks. > >Ramon Hildreth >--- >[ www.subudusa.org ] [ www.subudseattle.org ] >[ www.ramonred.com ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Changing row color with subroutine
Hi, I am having a little trouble with a sub that is using the modulus operator. It is called here-within a while loop: while (my $row = $sth->fetchrow_hashref()) { count++; color_rows( $count ) --some other stuff table cell value -some other stuff } --here is the sub sub color_rows { my $num = @_; my $bgcolor; If ( $num % 2 == 0 ) { $bgcolor="#bde6de"; } else { $bgcolor="white"; } return $bgcolor; }#end sub I expect that when the value that is passed in $count is even it will set the row color green, otherwise it will set it to white. What it is actually doing is setting the value white every time. Thanks. Ramon Hildreth --- [ www.subudusa.org ] [ www.subudseattle.org ] [ www.ramonred.com ]