There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer audio black screen boot bsod computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware network networking nvidia outlook outlook 2003 outlook express partition printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Perl MySQL query


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
malcolmd3111's Avatar
Member with 53 posts.
 
Join Date: Aug 2005
Experience: Intermediate
20-Apr-2008, 12:54 PM #1
Perl MySQL query
Hi,

I have a thorny problem that I cannot fix, so had to do a work around. Any wise Perl programmers out there have any insight?

Standard perl DBI interface; ****CODE SAMPLE****


my $dbh = DBI->connect("DBI:mysql:$db:$db_server",$dbuser,$dbpasswd)
or die "Can't connect to the DB: $DBI::errstr\n";

my $statement = "SELECT * FROM tblgenjnl WHERE law = '$jnl_law' AND week = '$jnl_week' AND quadrant_day = '$jnl_day'";

my $sth;

$sth = $dbh->prepare($statement)
or die "Couldn't prepare the query: $sth->errstr\n";

my $rv = $sth->execute()
or die "Couldn't execute the query: $dbh->errstr";

while(@row = $sth->fetchrow_array())
{
print "Law: $row[1]\t Quadrant: $row[2]\t Day: $row[3]\n Quote: \t $row[4]\n\n Source: $row[5]\n\n";
print "Entry: $row[6]\n Daily Guidance: $row[7] \n\n";
$quote = $row[4];
$source = $row[5];
$entry = $row[6];
$guidance = $row[7];
$text = $row[8];
}

my $rc = $sth->finish();
$rc = $dbh->disconnect;

After a few hours of digging I see that the while loop executes twice, fetching incorrect row data. I've attempted to understand why this would happen and cannot. So I wrote a work around which executes correctly.

........
while(@row = $sth->fetchrow_array())
{
print "Law: $row[1]\t Quadrant: $row[2]\t Day: $row[3]\n Quote: \t $row[4]\n\n Source: $row[5]\n\n";
print "Entry: $row[6]\n Daily Guidance: $row[7] \n\n";
$quote = $row[4];
$source = $row[5];
$entry = $row[6];
$guidance = $row[7];
$text = $row[8];
$meditation = $row[9];
last if $meditation ne "m";

}

I have a field in the db labelled "Meditation", I set the var $meditation to = "m" and within the db it never does. Therefore while loop only executes once now. This works fine thankfully.

However, I still don't know why the original code doesn't work? Any ideas?

many thanks.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:43 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.