I like creating multiple tables...
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

@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); } }
To get a name's worth of ips out you could then do..
$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


In reply to Re: Yet Another Half Perl Half mySQL Question by eejack
in thread Yet Another Half Perl Half mySQL Question by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.