in reply to Yet Another Half Perl Half mySQL Question
create table tbl_names ( id_name INT NOT NULL auto_increment, str_name VARCHAR(255), ); create table tbl_ipaddresses ( str_ipaddress VARCHAR(255), id_name INT, );
Then you can do schtuff like
To get a name's worth of ips out you could then do..@names = qw( firstname secondname ); @ips = ( "123.132.123.121" , "198.21.252.2" , "123.123.123.132"); $sql_statement = qq|INSERT INTO tbl_names (str_name) VALUES (?)|; $sth = $dbh->prepare($sql_statement); $sql_statement = qq|INSERT INTO tbl_ipaddresses (id_name, str_ipaddres +s) VALUES (?,?)|; $sth2 = $dbh->prepare($sql_statement); foreach $name (@names){ $rv = $sth->execute($name); my $id_name = $sth->{'insert_id'}; foreach $ip (@ips){ $rv = $sth2->execute($id_name, $ip); } }
$sql_statement = qq|select str_ipaddress from tbl_ipaddresses, tbl_names where tbl_names.str_name = 'firstname' and tbl_names.id_name = tbl_ipaddresses.id_name|; $sth = $dbh->prepare($sql_statement); $rv = $sth->execute; while ( ($ipaddress) = $sth->fetchrow_array ){ # do whatever }
EEjack
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Yet Another Half Perl Half mySQL Question
by jreades (Friar) on Jul 06, 2001 at 22:08 UTC | |
by eejack (Hermit) on Jul 06, 2001 at 23:15 UTC |