Chris,
    Thanks for you help.  I almost always see answers on this list that are
either faster, better, or cleaner.  And they come fast too.  I appreciate
the help that I have seen, received, and the things that I learn from
reading the list.

Gratefully,

Randy Peterman
Alt-N Technologies
www.altn.com

Helping the World Communicate.
----- Original Message -----
From: "Chris Winters" <[EMAIL PROTECTED]>
To: "Randy Peterman" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, March 29, 2001 9:16 AM
Subject: Re: $STH->{NAME}->[$Value] problem


> * Randy Peterman ([EMAIL PROTECTED]) [010329 10:02]:
> > Perl::DBI Friends,
> > In order to make my life somewhat easier (I think), I am using
JavaScript to
> > fill out an entire form rather than type out all of the array[refs] in
the
> > values field of each form.  I need to get an array of all of the Column
> > names since they are also identical to the field names (what a
coincidence),
> > however I am getting only two column names returned.
> >
> > The error I am getting is one where only the "FirstName" Column name is
> > returned and then the "StudentID" Column name is returned for the rest
of
> > the array, all 50 or so columns.  This is on an Access database, which
will
> > be converted into an SQL 2000 database after this early stage of
> > development.  Here's the snippet of code I'm currently using to get the
> > array.  I am only alerting the array for test purposes, to return the
value
> > immediately.
>
>
> > <CODE>
> > use strict;
> > use CGI;
> > use CGI::Carp qw(fatalsToBrowser);
> > use DBI;
> >
> > my $form = new CGI;
> >
> > if ($form->param("StudentID")){
> > PrintThePage($form);
> > }
> > else{
> > print "Location: main.html\n\n";
> > }
> >
> > #sub Print the Page
> > sub PrintThePage($form){
> > my $StudentID = $form->param("StudentID");
> > #connect to the Database
> > my $DBH = DBI->connect("DBI:ODBC:Registrar") or die "$!";
> > my $SQL = qq'SELECT * FROM StudentList WHERE StudentID = $StudentID';
> > my $STH = $DBH->prepare($SQL) or die $DBH->errstr();
> > $STH->execute() or die $STH->errstr();
> >
> > my @StudentInfo;
> > @StudentInfo = $STH->fetchrow_array();
> > ...
> > var StudentInfo = new Array(
> > ';
> > my $Value;
> > foreach $Value (@StudentInfo){
> > print " '".$Value."',\n";
> > }
> > print qq'\'\');
> > var ColNames = new Array(';
> > foreach $Value (@StudentInfo){
> > print " '". $STH->{NAME}->[$Value] ."',\n";
> > }
>
> $STH->{NAME} is an arrayref and $Value above is the value retrieved
> from the row, which is incorrect.
>
> Try something like this:
>
>  $STH->execute() || die $DBI::errstr;
>  my @student_info = $STH->fetchrow_array();
>
>  my @values = map { "'$_'" } @student_info;
>  my $js_value_array = join( ', ', @values );
>  print qq| var StudentInfo = new Array( $js_value_array );\n|;
>
>  my @names = map { "'$_'" } @{ $STH->{NAME} };
>  my $js_name_array = join( ', ', @names );
>  print qq| var ColNames = new Array( $js_name_array );\n|;
>
> HTH
>
> Chris
>
> --
> Chris Winters ([EMAIL PROTECTED])
> Building enterprise-capable snack solutions since 1988.
>


Reply via email to