in reply to Need help writing a script that interacts with a MySQL DB!

Instead of using this logic of $index, why can't you simply print the name and email column by using something like this:
my @results; while (@results = $query1->fetchrow_array()) { print "Name : $results[1], Email: $results[2]\n"; }

Generally, first row consist of ID. That's why, Here I'm assuming that after ID the 1st column is for name and 2nd column is for email address. Please, use the correct column number as in your table.

Also, for printing all the rows, you can use like this:

my @results; while (@results = $query1->fetchrow_array()) { foreach my $r (@row) { print "$r\n"; } }
let me know if you still have any query.

Regards, CKJ

Replies are listed 'Best First'.
Re^2: Need help writing a script that interacts with a MySQL DB!
by CountZero (Bishop) on Sep 30, 2012 at 07:36 UTC
    Here I'm assuming that 1st column is for name and 2nd column is for email address, you can use the correct column number here.
    Since Perl arrays are zero-based, your
    print "Name : $results[1], Email: $results[2]\n";
    should be
    print "Name : $results[0], Email: $results[1]\n";

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics