Re: Can someone tell me what is wrong with this?
From: cp (cpryce_at_nospam.pryce.net)
Date: 01/29/04
- Next message: ctcgag_at_hotmail.com: "Re: File handle re-use woes using pipe within a loop"
- Previous message: Nigel Scott: "Help with a regexp please"
- In reply to: Big Swifty: "Can someone tell me what is wrong with this?"
- Next in thread: Big Swifty: "Re: Can someone tell me what is wrong with this?"
- Reply: Big Swifty: "Re: Can someone tell me what is wrong with this?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jan 2004 10:51:48 -0600
In article <Xns947F6B850158Ckburdishoptonlinenet@167.206.3.2>, Big
Swifty <bigswifty00000@yahoo.com> wrote:
> sure I'm doing it wrong!!!
> I get back some rows from the database, and then want to put those values
> in checkboxes that if selected, will be then be used to select specific
> rows from another table.
> The first line works with the variables, but the checkbox line does not!!
Do you go to the doctor and mutter, "I'm not feeling so well?" And
then, not give enough specifics for a diagnosis?
Define 'does not work'? What did you expect it to do. What did it do
instead? Did it produce an error or warning ?
> I tried quoting and unquoting and requoting etc etc!!!
> Where am I going wrong???
>
>
> foreach (@documents) {
> ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> [$counter+1], $documents[$counter+2];
you're looping through each item in an array. Then you're using the
first three elements of that array each iteration, offest by one each
time you loop through. Not, I think, what you have in mind. And I'm not
sure why you're using those variables anyway. If all your going to do
is assign it to values of a CGI fucntion call?
What is actually in @documents? If it is the result of a database
query, is it perhaps an array of arrayrefs?
Generally, if you have the results of a database query in an array of
array refs, you would want a loop lik :
# untested
foreach my $row ( @documents ) {
print qq(<PRE><TT><B>$row->[0] $row->[1] $row->[2]</B></TT></PRE>),
$q->checkbox(-name=>$row->[0],-value=>'YES',
-label=>$row->[0] );
}
or a more idiomatic version, eliminating the array in the first place
# prepare and execute a query,
my $sth = $dbh->prepare( $some_sql_statement );
$sth->execute();
# more untested code
my $row;
while ( $row = $sth->fetchrow_arrayref() ) {
print qq(<PRE><TT><B>$row->[0] $row->[1] $row->[2]</B></TT></PRE>),
$q->checkbox(-name=>$row->[0],-value=>'YES',
-label=>$row->[0] );
}
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> # PREVIOUS LINE WORKS
Define 'works'
> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
> $doc_name);
> # NOT LINE ABOVE
define 'Not line above'
> $counter ++;
> }
-- cp
- Next message: ctcgag_at_hotmail.com: "Re: File handle re-use woes using pipe within a loop"
- Previous message: Nigel Scott: "Help with a regexp please"
- In reply to: Big Swifty: "Can someone tell me what is wrong with this?"
- Next in thread: Big Swifty: "Re: Can someone tell me what is wrong with this?"
- Reply: Big Swifty: "Re: Can someone tell me what is wrong with this?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|