loading a lot of values into an mysql database and looping

N

Nikos

Eric said:
Your columns are named differently when you create the table and when
you try to populate it (onoma, description, counter in the first case,
and name, description, count in the second). I suspect this might be
relevant.

-=Eric

Just shoot me Eric :)

You are rigth i changes it back and now the table game shas
smethigncalled <MEMO> in it.

now the scripot is like this( i changes from the beginning all the
columns names to match in greek words)

in games.pl is:

while ( $st->fetchrow_hashref ) {

print table( {class=>'info'},
Tr(
td( submit( -name=>'game', -value=>$_->{onoma} )),
td( $_->{perigrafi} ),
td( $_->{metritis} )
)
)
}

and in make.pl is:

$dbh->do( "create table games( onoma text, perigrafi text, metritis int
)" ) or die $!;

#===============================================================================

my $sth = $dbh->prepare( "INSERT INTO games( onoma, perigrafi, metritis)
VALUES (?, ?, ?)" );

open (FILE, "<../data/games/perigrafes.txt") or die "Can't open FILE: $!\n";
while (<FILE>) {
chomp;
my @row = split /\t/;

my $num = scalar @row;
if ($num == 2)
{
push @row, 0;
unless ( $sth->execute(@row) ) { warn $dbh->errstr; }
if ($dbh->errstr)
{
warn "LINE $.: INSERT '$row[0]': $dbh->errstr\n";
}
}
else
{
warn "Error in line $.: number of fields $num\n";
}
}
close FILE;

#===============================================================================

Iam sorry about my carefullness but i was a bit dizzy trying so many
hours...
 
N

Nikos

As far as the maek.pl is concerned i cnahed it to:

#===============================================================================

my @row;
my $sth = $dbh->prepare( "INSERT INTO games( onoma, perigrafi, metritis)
VALUES (?, ?, ?)" );

open (FILE, "<../data/games/perigrafes.txt") or die $!;
while (<FILE>) {
chomp;

@row = split /\t/;
push @row, 0;

$sth->execute( @row );
}
close FILE;

#===============================================================================

and is fine now! ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top