Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks!!!... if(@pics) # this array has a max of 4 pic names { my $dbh = SQLStuff->connect_mysql(); my $sth = $dbh->prepare("select * from test_users where user = ? " +) or &justdie("Can't select from table: ",$dbh->errmsg); $sth->execute($got_user_name); # I am using this thinking that if $flag_pic returns true there + is already a duplicated pic in the database and # I dont have to do the INSERT my $flag_pic==0; while (my $row = $sth->fetchrow_hashref()) { if(($row->{image_name_1} ne "") eq ($pics[0] ne "")){$flag_pic +=1;} if(($row->{image_name_2} ne "") eq ($pics[1] ne "")){$flag_pic +=1;} if(($row->{image_name_3} ne "") eq ($pics[2] ne "")){$flag_pic +=1;} if(($row->{image_name_4} ne "") eq ($pics[3] ne "")){$flag_pic +=1;} } print "<br>**$flag_pic**<br>"; if($flag_pic == 0) # only do this if $flag_pic is not true or equa +l to 0. { my $dbh = SQLStuff->connect_mysql(); my $sth = $dbh->prepare("insert into test_add(image_1,image_2,i +mage_3,image_4,image_loc,user) values(?, ?, ?, ?, ?,?)") or &justdie("Can't add data, please try again later! ",$dbh->e +rrmsg); $sth->execute((@pics, undef, undef, undef, undef)[0..3],$path_l +oc[0],$got_user) or &justdie("Can't select from table: ",$dbh->errmsg +); } } ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to match elements of array
by PeterPeiGuo (Hermit) on Dec 03, 2010 at 03:38 UTC | |
|
Re: How to match elements of array
by samarzone (Pilgrim) on Dec 03, 2010 at 07:42 UTC | |
by Anonymous Monk on Dec 03, 2010 at 12:01 UTC | |
|
Re: How to match elements of array
by chrestomanci (Priest) on Dec 03, 2010 at 13:19 UTC | |
by Anonymous Monk on Dec 03, 2010 at 18:29 UTC |