PDA

View Full Version : Turn DB info into Array


ynotlim
09-09-2006, 01:41 AM
I have the following array. These major codes are now in a DB. How do I store them into the array from the DB??

@major_list = ( "77279", "60014", "65063", "97068", "60093", "5744D", "57000",
"60100", "55120", "77289", "7728B", "77294", "62153", "0616A", "60469",
"77284", "60169", "60174", "60192", "77302", "95201", "77193", "95193",
);

here is what I have so far. but it doesn't work.

@major_list;
$dbh = DBI->connect('DBI:....)
or warn "Unable to open: $DBI::errst \n";

$con = $dbh ->prepare(select major_code from major
where active=1 order);
$con ->execute;
while ( @columns = $cursor->fetchrow ) {
@ws = ( map {"$_"} @columns);
@major_list=($ws[0]);
}
$con->finish;
$dbh->disconnect;

Thanks in advance
Tony

FishMonger
09-09-2006, 02:41 AM
$dbh = DBI->connect('DBI:....)
or warn "Unable to open: $DBI::errst \n";

$con = $dbh->prepare("select major_code from major where active=1");
$con->execute;
while ( @columns = $cursor->fetchrow_array ) {
push @major_list, @columns;
}

or
$dbh = DBI->connect('DBI:....)
or warn "Unable to open: $DBI::errst \n";

$major_list = $dbh->selectcol_arrayref("select major_code from major where active=1");$major_list is a reference to an array. You can loop through it like this:foreach $code (@$major_list) {
print "code: $code\n;
}

ynotlim
09-11-2006, 06:21 PM
thanks Fishmonger, it's working great.