PDA

View Full Version : Array Problem


ynotlim
09-11-2006, 07:34 PM
I have an array of @major_used

@major_used = ("00000", "12345", etc)

I want to print all the majors in my majors database, except those that are in the array @major_used.


$cursor = $dbh ->prepare($SQL);
$cursor ->execute;

while ( @columns = $cursor->fetchrow ) {
@ws = ( map {"$_"} @columns);
$major_code = $ws[0];
$major_names = $ws[1];
$major_used=@major_used;
for($i=0;$i<$major_used;$i++)
{
if ($major_code != $major_used[$i]){
print "<INPUT TYPE=\"text\" NAME=\"$major_code\" SIZE=\"2\" MAXLENGTH=\"2\" STYLE=\"font-size: 8pt\">$major{$major_code}<BR>";
}
}}
$cursor->finish;
$dbh->disconnect;


What i need it to do is if $major_code = $major_used, exit the for loop and continue with the while loop. How do I do that??

thanks in advance,

Tony

ynotlim
09-11-2006, 07:56 PM
is there some way i can put the for loop into the if statement?

FishMonger
09-11-2006, 09:31 PM
You are doing several things that are unnecessary and it would be best/easier to use a hash instead of the array(s).

There is no reason to have any of these lines.@ws = ( map {"$_"} @columns);
$major_code = $ws[0];
$major_names = $ws[1];
$major_used=@major_used;
How did you build the @major_used array? If the @major_used array was built from a DB query just prior to this one, it might be best to combine that query and this one into a single query, otherwise it probably would be best to build your select statement so that is excludes the items from the @major_used array.

ynotlim
09-12-2006, 06:46 PM
Thanks fish monger, I added a flag so that if the major_used was in the database, it would be a 1. Everything is working fine now.

Tony