Re: Can someone tell me what is wrong with this?

From: cp (cpryce_at_nospam.pryce.net)
Date: 01/29/04


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


Relevant Pages

  • Re: How do you create a checkbox in a column?
    ... Is it a query or table? ... Instead of working within the old database, ... Also, for the text boxes, when I view the database ... In rearranging the columns with checkboxes, ...
    (microsoft.public.access.gettingstarted)
  • Re: yes/no checkmarks PLEASE HELP
    ... each with 60 colmns of yes/no checkboxes ... >> QUERY. ... You can't simply find and replace an entire database. ... >>> Idyllwild Fire Protection District ...
    (microsoft.public.access.tablesdbdesign)
  • Re: How can I code to get more than One value from checkbox?
    ... >>I think you're confusing checkboxes and radio buttons. ... loop twice, with qtype being set to "project" the first time and "blame" ... It doesn't make sense to connect to the database each time round the ... Unfortunately the assignment to query isn;t a syntax error in Python ...
    (comp.lang.python)
  • Re: form - request question
    ... Name your desired variables, loop through the $_POST/$_GET array, ... these names are used to build the query. ... column names in de database. ... you''d change the location or surrounding code of the script it could break. ...
    (alt.php)
  • Re: Count rows in dataset WHERE ...
    ... This will return an array of rows matching the ... things you can do in a database query, and it is certainly going to be far ... less efficient then a SQL engine that has query optimization, ...
    (microsoft.public.dotnet.framework.adonet)